Skip to content

Instantly share code, notes, and snippets.

@brycebaril
Created March 27, 2014 19:53
Show Gist options
  • Save brycebaril/9816749 to your computer and use it in GitHub Desktop.
Save brycebaril/9816749 to your computer and use it in GitHub Desktop.
Split a file into a file per line of the input file.
var fs = require("fs")
var split = require("binary-split")
var terminus = require("terminus")
var path = require("path")
var input = process.argv[2]
var dir = path.dirname(input)
var basename = path.basename(input)
var count = 0
fs.createReadStream(input)
.pipe(split())
.pipe(terminus(function (chunk, encoding, callback) {
fs.appendFile(path.join(dir, count + "_" + basename), chunk)
count++
callback()
}))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment