Skip to content

Instantly share code, notes, and snippets.

@fergiemcdowall
Last active August 29, 2015 14:05
Show Gist options
  • Save fergiemcdowall/843f363165ca5f5ae2d2 to your computer and use it in GitHub Desktop.
Save fergiemcdowall/843f363165ca5f5ae2d2 to your computer and use it in GitHub Desktop.
How to pipe a file of key-value pairs into levelUP
{"key":"john","value":"lennon"}
{"key":"paul","value":"mccartney"}
{"key":"ringo","value":"starr"}
{"key":"george","value":"harrison"}
{
"dependencies": {
"level": "*",
"JSONStream" : "*"
}
}
var level = require('level'),
db = level('./mydb'),
JSONStream = require('JSONStream'),
fs = require('fs');
fs.createReadStream('backup.json')
.pipe(JSONStream.parse())
.pipe(db.createWriteStream({"type":"put"}));
@fergiemcdowall
Copy link
Author

As discussed here: Level/levelup#274

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment