UNPKG

reactive-superglue

Version:

Stream-based middleware for I/O integration of sources and sinks

42 lines (35 loc) 1.07 kB
var _=require("highland") var Stream=_().constructor var fs=require("fs") Stream.prototype.json=function(file){ var str=this.map(JSON.stringify).map(x=>x+"\n") if(!file) return str; return str.file(file); } Stream.prototype.to_file=function(file){ _([file]).flatMap(_.wrapCallback(fs.createWriteStream)) } Stream.prototype.zip=function(file){ //TODO } Stream.prototype.csv=function(file, headers_flag){ //TODO } Stream.prototype.json_parse=function(){ return this.map(JSON.parse) } Stream.prototype.csv_parse=function(parser, header_parser){ var headers; if(header_parser){ if(typeof header_parser!=="function") { header_parser=function(record){ } } } if(!parser) parser=function(record){ } } //Stream.prototype.upsert=function(collection){return this.consume(collection.upsert())} //Stream.prototype.insert=function(collection){return this.consume(collection.insert())} //Stream.prototype.remove=function(collection){return this.consume(collection.remove())} module.exports=_;