Created
March 22, 2021 01:24
-
-
Save sam-heller/c8253a07d79f20cf14cf1613e34fbfcf to your computer and use it in GitHub Desktop.
Spltting a buffer apart and reassembling
This file contains 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'); | |
const split = require('split-buffer') | |
let data = fs.readFileSync('build/test.json') | |
let buffers = split(data, 100000) | |
fs.writeFileSync('b1', buffers[0]) | |
fs.writeFileSync('b2', buffers[1]) | |
fs.writeFileSync('b3', buffers[2]) | |
let rebuild = Buffer.concat([fs.readFileSync('b1'), fs.readFileSync('b2'), fs.readFileSync('b3')]); | |
console.log(Buffer.compare(data, rebuild)); | |
fs.writeFileSync('build/rebuilt.json', rebuild) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment