Skip to content

Instantly share code, notes, and snippets.

@sam-heller
Created March 22, 2021 01:24
Show Gist options
  • Save sam-heller/c8253a07d79f20cf14cf1613e34fbfcf to your computer and use it in GitHub Desktop.
Save sam-heller/c8253a07d79f20cf14cf1613e34fbfcf to your computer and use it in GitHub Desktop.
Spltting a buffer apart and reassembling
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