memory-stream
Advanced tools
Comparing version 0.0.2 to 0.0.3
14
index.js
@@ -30,4 +30,5 @@ var Stream = require("stream").Stream; | ||
this.buffer.push(new Buffer(chunk)); | ||
} | ||
else { | ||
} else if (this._writableState.objectMode) { | ||
this.buffer.push(Buffer.isBuffer(chunk) ? JSON.parse(chunk) : chunk); | ||
} else { | ||
this.buffer.push(chunk); | ||
@@ -41,4 +42,3 @@ } | ||
return this.buffer; | ||
} | ||
else { | ||
} else { | ||
return this.toBuffer(); | ||
@@ -51,4 +51,3 @@ } | ||
JSON.stringify(this.buffer); | ||
} | ||
else { | ||
} else { | ||
return this.buffer.join(''); | ||
@@ -61,4 +60,3 @@ } | ||
return new Buffer(this.toString()); | ||
} | ||
else { | ||
} else { | ||
return Buffer.concat(this.buffer); | ||
@@ -65,0 +63,0 @@ } |
{ | ||
"name": "memory-stream", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "Node.js streams implementation for buffered memory writes", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
var fs = require('fs'); | ||
var path = require('path'); | ||
var assert = require('assert'); | ||
var source = path.join(process.cwd(), 'test/source.txt'); | ||
var gold = fs.readFileSync(source); | ||
var MemoryStream = require('../../index.js'); | ||
@@ -11,16 +9,36 @@ | ||
test('Stream file', function(done) { | ||
var rs = fs.createReadStream(source); | ||
var ws = new MemoryStream(); | ||
var source = path.join(process.cwd(), 'test/source.txt'); | ||
var gold = fs.readFileSync(source); | ||
var rs = fs.createReadStream(source); | ||
var ws = new MemoryStream(); | ||
ws.on('finish', function() { | ||
// console.log(gold.toString()); | ||
// console.log(ws.get().toString()); | ||
assert.equal(ws.get().toString(), gold.toString(), 'Output should equal file source.'); | ||
done(); | ||
}); | ||
ws.on('finish', function() { | ||
// console.log(gold.toString()); | ||
// console.log(ws.get().toString()); | ||
assert.equal(ws.get().toString(), gold.toString(), 'Output should equal file source.'); | ||
done(); | ||
}); | ||
rs.pipe(ws); | ||
rs.pipe(ws); | ||
}); | ||
test('Stream file objectMode true', function(done) { | ||
var source = path.join(process.cwd(), 'test/object.json'); | ||
var gold = require(source); | ||
var rs = fs.createReadStream(source); | ||
var ws = new MemoryStream({ | ||
objectMode: true | ||
}); | ||
ws.on('finish', function() { | ||
console.error(ws.get(), gold); | ||
assert.deepEqual(ws.get(), [gold], 'Output should equal file source.'); | ||
done(); | ||
}); | ||
rs.pipe(ws); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4845
8
85
2