First upload version 0.0.1
This commit is contained in:
21
node_modules/memory-stream/LICENSE
generated
vendored
Normal file
21
node_modules/memory-stream/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 Tommy Messbauer
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
20
node_modules/memory-stream/README.md
generated
vendored
Normal file
20
node_modules/memory-stream/README.md
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
memory-stream
|
||||
=============
|
||||
|
||||
Node.js streams implementation for buffered memory writes.
|
||||
|
||||
# Usage
|
||||
|
||||
```javascript
|
||||
var fs = require('fs');
|
||||
var MemoryStream = require('memory-stream');
|
||||
|
||||
var rs = fs.createReadStream('source.txt');
|
||||
var ws = new MemoryStream();
|
||||
|
||||
ws.on('finish', function() {
|
||||
console.log(ws.toString());
|
||||
});
|
||||
|
||||
rs.pipe(ws);
|
||||
```
|
||||
62
node_modules/memory-stream/index.js
generated
vendored
Normal file
62
node_modules/memory-stream/index.js
generated
vendored
Normal file
@@ -0,0 +1,62 @@
|
||||
var Stream = require("stream").Stream;
|
||||
var util = require('util');
|
||||
|
||||
// For Node 0.8 users
|
||||
if (!Stream.Writable) {
|
||||
Stream = require('readable-stream')
|
||||
}
|
||||
|
||||
// Internal proto for buffering memory stream
|
||||
var MemoryStream = function(options) {
|
||||
if (!(this instanceof MemoryStream)) {
|
||||
return new MemoryStream();
|
||||
}
|
||||
|
||||
this.options = options = options || {};
|
||||
if (!this.options.encoding && !this.options.objectMode) {
|
||||
this.options.encoding = 'Buffer';
|
||||
}
|
||||
|
||||
Stream.Writable.call(this, options);
|
||||
this.buffer = [];
|
||||
|
||||
};
|
||||
|
||||
util.inherits(MemoryStream, Stream.Writable);
|
||||
|
||||
MemoryStream.prototype._write = function(chunk, encoding, cb) {
|
||||
if (!this._writableState.objectMode && this.options.encoding === 'Buffer' && encoding === 'utf8') {
|
||||
this.buffer.push(new Buffer(chunk));
|
||||
} else if (this._writableState.objectMode) {
|
||||
this.buffer.push(Buffer.isBuffer(chunk) ? JSON.parse(chunk) : chunk);
|
||||
} else {
|
||||
this.buffer.push(chunk);
|
||||
}
|
||||
cb();
|
||||
};
|
||||
|
||||
MemoryStream.prototype.get = function() {
|
||||
if (this._writableState.objectMode) {
|
||||
return this.buffer;
|
||||
} else {
|
||||
return this.toBuffer();
|
||||
}
|
||||
};
|
||||
|
||||
MemoryStream.prototype.toString = function() {
|
||||
if (this._writableState.objectMode) {
|
||||
JSON.stringify(this.buffer);
|
||||
} else {
|
||||
return this.buffer.join('');
|
||||
}
|
||||
};
|
||||
|
||||
MemoryStream.prototype.toBuffer = function() {
|
||||
if (this._writableState.objectMode) {
|
||||
return new Buffer(this.toString());
|
||||
} else {
|
||||
return Buffer.concat(this.buffer);
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = MemoryStream;
|
||||
31
node_modules/memory-stream/package.json
generated
vendored
Normal file
31
node_modules/memory-stream/package.json
generated
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
{
|
||||
"name": "memory-stream",
|
||||
"version": "1.0.0",
|
||||
"description": "Node.js streams implementation for buffered memory writes",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "./node_modules/tape/bin/tape test/tests/*.js | tap-spec"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/doanythingfordethklok/memory-stream.git"
|
||||
},
|
||||
"keywords": [
|
||||
"streams",
|
||||
"memory",
|
||||
"buffer"
|
||||
],
|
||||
"author": "Tommy Messbauer",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/doanythingfordethklok/memory-stream/issues"
|
||||
},
|
||||
"homepage": "https://github.com/doanythingfordethklok/memory-stream",
|
||||
"dependencies": {
|
||||
"readable-stream": "^3.4.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"tap-spec": "^5.0.0",
|
||||
"tape": "^4.11.0"
|
||||
}
|
||||
}
|
||||
4
node_modules/memory-stream/test/object.json
generated
vendored
Normal file
4
node_modules/memory-stream/test/object.json
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"dogs": "bark",
|
||||
"cats": "are on the internet"
|
||||
}
|
||||
1
node_modules/memory-stream/test/source.txt
generated
vendored
Normal file
1
node_modules/memory-stream/test/source.txt
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
abcdefghijklmnopqrstuvwxyz
|
||||
39
node_modules/memory-stream/test/tests/unit.js
generated
vendored
Normal file
39
node_modules/memory-stream/test/tests/unit.js
generated
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var test = require('tape');
|
||||
var MemoryStream = require('../../index.js');
|
||||
|
||||
test('Stream file', function (t) {
|
||||
t.plan(1);
|
||||
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());
|
||||
t.equal(ws.get().toString(), gold.toString(), 'Output should equal file source.');
|
||||
t.end();
|
||||
});
|
||||
|
||||
rs.pipe(ws);
|
||||
});
|
||||
|
||||
test('Stream file objectMode true', function (t) {
|
||||
t.plan(1);
|
||||
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);
|
||||
t.deepEqual(ws.get(), [ gold ], 'Output should equal file source.');
|
||||
t.end();
|
||||
});
|
||||
|
||||
rs.pipe(ws);
|
||||
});
|
||||
Reference in New Issue
Block a user