Created
September 12, 2018 03:32
-
-
Save chulman444/47aca652c72d8208ddbf0f1ff1ed09e4 to your computer and use it in GitHub Desktop.
Converts { type: "Buffer", data: [1,2,3,4,...] } to a proper 'raw' file. π² WOW π² Such π USEFUL π
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require("fs"); | |
function createParser() { | |
const ArgumentParser = require("argparse").ArgumentParser; | |
const parser = new ArgumentParser({ }); | |
parser.addArgument( | |
['filepath'], | |
{ | |
type: String, | |
help: "Filepath to the data packet" | |
} | |
); | |
parser.addArgument( | |
['-o', '--output'] | |
) | |
return parser; | |
} | |
function main() { | |
const parser = createParser(); | |
const args = parser.parseArgs(); | |
const filepath = args["filepath"]; | |
const output_path = args["output"] | |
const payload_data = getDataFromFile(filepath); | |
const buf = Buffer.from(payload_data); | |
console.log(buf.toString()); | |
if(output_path !== null) { | |
fs.writeFileSync(output_path, buf); | |
} | |
} | |
function getDataFromFile(filepath) { | |
const file_content = fs.readFileSync(filepath); | |
const json_content = JSON.parse(file_content); | |
const payload = json_content["payload"]; | |
const payload_data = payload["data"]; | |
return payload_data | |
} | |
main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment