[Pkg-javascript-commits] [node-fd-slicer] 02/03: Imported Upstream version 1.0.1
Andrew Kelley
andrewrk-guest at moszumanska.debian.org
Sat May 16 17:25:14 UTC 2015
This is an automated email from the git hooks/post-receive script.
andrewrk-guest pushed a commit to branch master
in repository node-fd-slicer.
commit d859374b0cac24ca37c6f576843bb8d0b7408dfa
Author: Andrew Kelley <superjoe30 at gmail.com>
Date: Sat May 16 17:21:06 2015 +0000
Imported Upstream version 1.0.1
---
.gitignore | 1 +
.travis.yml | 7 +++
CHANGELOG.md | 14 +++++
README.md | 45 ++++++++++++---
index.js | 107 ++++++++++++++++++++++++++++++++++--
package.json | 20 +++++--
test/test.js | 175 ++++++++++++++++++++++++++++++++++++++++++++++-------------
7 files changed, 310 insertions(+), 59 deletions(-)
diff --git a/.gitignore b/.gitignore
index 07e6e47..ccc2930 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,2 @@
+/coverage
/node_modules
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..77b7202
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,7 @@
+language: node_js
+node_js:
+ - "0.10"
+script:
+ - "npm run test-travis"
+after_script:
+ - "npm install coveralls at 2 && cat ./coverage/lcov.info | ./node_modules/.bin/coveralls"
diff --git a/CHANGELOG.md b/CHANGELOG.md
index b1810c5..783042f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,17 @@
+### 1.0.1
+
+ * use `setImmediate` instead of `nextTick`
+
+### 1.0.0
+
+ * `new FdSlicer(fd, options)` must now be `fdSlicer.createFromFd(fd, options)`
+ * fix behavior when `end` is 0.
+ * fix `createWriteStream` when using `createFromBuffer`
+
+### 0.4.0
+
+ * add ability to create an FdSlicer instance from a Buffer
+
### 0.3.2
* fix write stream and read stream destroy behavior
diff --git a/README.md b/README.md
index c83a0b7..5787c1a 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,8 @@
# fd-slicer
+[![Build Status](https://travis-ci.org/andrewrk/node-fd-slicer.svg?branch=master)](https://travis-ci.org/andrewrk/node-fd-slicer)
+[![Coverage Status](https://img.shields.io/coveralls/andrewrk/node-fd-slicer.svg)](https://coveralls.io/r/andrewrk/node-fd-slicer)
+
Safe `fs.ReadStream` and `fs.WriteStream` using the same fd.
Let's say that you want to perform a parallel upload of a file to a remote
@@ -36,18 +39,20 @@ This module also gives you some additional power that the builtin
* Emitting a 'progress' event on write.
* Ability to set a maximum size and emit an error if this size is exceeded.
+ * Ability to create an `FdSlicer` instance from a `Buffer`. This enables you
+ to provide API for handling files as well as buffers using the same API.
## Usage
```js
-var FdSlicer = require('fd-slicer');
+var fdSlicer = require('fd-slicer');
var fs = require('fs');
fs.open("file.txt", 'r', function(err, fd) {
if (err) throw err;
- var fdSlicer = new FdSlicer(fd);
- var firstPart = fdSlicer.createReadStream({start: 0, end: 100});
- var secondPart = fdSlicer.createReadStream({start: 100});
+ var slicer = fdSlicer.createFromFd(fd);
+ var firstPart = slicer.createReadStream({start: 0, end: 100});
+ var secondPart = slicer.createReadStream({start: 100});
var firstOut = fs.createWriteStream("first.txt");
var secondOut = fs.createWriteStream("second.txt");
firstPart.pipe(firstOut);
@@ -55,15 +60,28 @@ fs.open("file.txt", 'r', function(err, fd) {
});
```
+You can also create from a buffer:
+
+```js
+var fdSlicer = require('fd-slicer');
+var slicer = FdSlicer.createFromBuffer(someBuffer);
+var firstPart = slicer.createReadStream({start: 0, end: 100});
+var secondPart = slicer.createReadStream({start: 100});
+var firstOut = fs.createWriteStream("first.txt");
+var secondOut = fs.createWriteStream("second.txt");
+firstPart.pipe(firstOut);
+secondPart.pipe(secondOut);
+```
+
## API Documentation
-### FdSlicer(fd, [options])
+### fdSlicer.createFromFd(fd, [options])
```js
-var FdSlicer = require('fd-slicer');
+var fdSlicer = require('fd-slicer');
fs.open("file.txt", 'r', function(err, fd) {
if (err) throw err;
- var fdSlicer = new FdSlicer(fd);
+ var slicer = fdSlicer.createFromFd(fd);
// ...
});
```
@@ -79,11 +97,19 @@ to use `createWriteStream` make sure you open it for writing.
`false`. `ref()` and `unref()` can be used to increase or decrease the
reference count, respectively.
+### fdSlicer.createFromBuffer(buffer)
+
+```js
+var fdSlicer = require('fd-slicer');
+var slicer = fdSlicer.createFromBuffer(someBuffer);
+// ...
+```
+
#### Properties
##### fd
-The file descriptor passed in.
+The file descriptor passed in. `undefined` if created from a buffer.
#### Methods
@@ -159,4 +185,5 @@ Emitted if `fs.close` returns an error when auto closing.
##### 'close'
-Emitted when fd-slicer closes the file descriptor due to `autoClose`.
+Emitted when fd-slicer closes the file descriptor due to `autoClose`. Never
+emitted if created from a buffer.
diff --git a/index.js b/index.js
index d762645..140e003 100644
--- a/index.js
+++ b/index.js
@@ -3,10 +3,14 @@ var util = require('util');
var stream = require('stream');
var Readable = stream.Readable;
var Writable = stream.Writable;
+var PassThrough = stream.PassThrough;
var Pend = require('pend');
var EventEmitter = require('events').EventEmitter;
-module.exports = FdSlicer;
+exports.createFromBuffer = createFromBuffer;
+exports.createFromFd = createFromFd;
+exports.BufferSlicer = BufferSlicer;
+exports.FdSlicer = FdSlicer;
util.inherits(FdSlicer, EventEmitter);
function FdSlicer(fd, options) {
@@ -81,7 +85,7 @@ function ReadStream(context, options) {
this.context.ref();
this.start = options.start || 0;
- this.end = options.end;
+ this.endOffset = options.end;
this.pos = this.start;
this.destroyed = false;
}
@@ -91,8 +95,8 @@ ReadStream.prototype._read = function(n) {
if (self.destroyed) return;
var toRead = Math.min(self._readableState.highWaterMark, n);
- if (self.end != null) {
- toRead = Math.min(toRead, self.end - self.pos);
+ if (self.endOffset != null) {
+ toRead = Math.min(toRead, self.endOffset - self.pos);
}
if (toRead <= 0) {
self.destroyed = true;
@@ -136,7 +140,7 @@ function WriteStream(context, options) {
this.context.ref();
this.start = options.start || 0;
- this.endOffset = options.end || Infinity;
+ this.endOffset = (options.end == null) ? Infinity : +options.end;
this.bytesWritten = 0;
this.pos = this.start;
this.destroyed = false;
@@ -178,3 +182,96 @@ WriteStream.prototype.destroy = function() {
this.destroyed = true;
this.context.unref();
};
+
+util.inherits(BufferSlicer, EventEmitter);
+function BufferSlicer(buffer) {
+ EventEmitter.call(this);
+
+ this.refCount = 0;
+ this.buffer = buffer;
+}
+
+BufferSlicer.prototype.read = function(buffer, offset, length, position, callback) {
+ var end = position + length;
+ var delta = end - this.buffer.length;
+ var written = (delta > 0) ? delta : length;
+ this.buffer.copy(buffer, offset, position, end);
+ setImmediate(function() {
+ callback(null, written);
+ });
+};
+
+BufferSlicer.prototype.write = function(buffer, offset, length, position, callback) {
+ buffer.copy(this.buffer, position, offset, offset + length);
+ setImmediate(function() {
+ callback(null, length, buffer);
+ });
+};
+
+BufferSlicer.prototype.createReadStream = function(options) {
+ options = options || {};
+ var readStream = new PassThrough(options);
+ readStream.start = options.start || 0;
+ readStream.endOffset = options.end;
+ readStream.pos = readStream.endOffset || this.buffer.length; // yep, we're already done
+ readStream.destroyed = false;
+ readStream.write(this.buffer.slice(readStream.start, readStream.pos));
+ readStream.end();
+ readStream.destroy = function() {
+ readStream.destroyed = true;
+ };
+ return readStream;
+};
+
+BufferSlicer.prototype.createWriteStream = function(options) {
+ var bufferSlicer = this;
+ options = options || {};
+ var writeStream = new Writable(options);
+ writeStream.start = options.start || 0;
+ writeStream.endOffset = (options.end == null) ? this.buffer.length : +options.end;
+ writeStream.bytesWritten = 0;
+ writeStream.pos = writeStream.start;
+ writeStream.destroyed = false;
+ writeStream._write = function(buffer, encoding, callback) {
+ if (writeStream.destroyed) return;
+
+ var end = writeStream.pos + buffer.length;
+ if (end > writeStream.endOffset) {
+ var err = new Error("maximum file length exceeded");
+ err.code = 'ETOOBIG';
+ writeStream.destroyed = true;
+ callback(err);
+ return;
+ }
+ buffer.copy(bufferSlicer.buffer, writeStream.pos, 0, buffer.length);
+
+ writeStream.bytesWritten += buffer.length;
+ writeStream.pos = end;
+ writeStream.emit('progress');
+ callback();
+ };
+ writeStream.destroy = function() {
+ writeStream.destroyed = true;
+ };
+ return writeStream;
+};
+
+BufferSlicer.prototype.ref = function() {
+ this.refCount += 1;
+};
+
+BufferSlicer.prototype.unref = function() {
+ this.refCount -= 1;
+
+ if (this.refCount < 0) {
+ throw new Error("invalid unref");
+ }
+};
+
+function createFromBuffer(buffer) {
+ return new BufferSlicer(buffer);
+}
+
+function createFromFd(fd, options) {
+ return new FdSlicer(fd, options);
+}
diff --git a/package.json b/package.json
index cb6aa0f..ca5c9c0 100644
--- a/package.json
+++ b/package.json
@@ -1,19 +1,23 @@
{
"name": "fd-slicer",
- "version": "0.3.2",
+ "version": "1.0.1",
"description": "safely create multiple ReadStream or WriteStream objects from the same file descriptor",
"main": "index.js",
"scripts": {
- "test": "mocha --reporter spec"
+ "test": "mocha --reporter spec --check-leaks",
+ "test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot --check-leaks test/test.js",
+ "test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --timeout 10000 --reporter spec --check-leaks test/test.js"
},
"author": "Andrew Kelley <superjoe30 at gmail.com>",
"license": "MIT",
"devDependencies": {
- "mocha": "~1.21.5",
- "stream-equal": "~0.1.5"
+ "istanbul": "~0.3.3",
+ "mocha": "~2.0.1",
+ "stream-equal": "~0.1.5",
+ "streamsink": "~1.2.0"
},
"dependencies": {
- "pend": "~1.1.3"
+ "pend": "~1.2.0"
},
"directories": {
"test": "test"
@@ -24,5 +28,9 @@
},
"bugs": {
"url": "https://github.com/andrewrk/node-fd-slicer/issues"
- }
+ },
+ "keywords": [
+ "createReadStream",
+ "createWriteStream"
+ ]
}
diff --git a/test/test.js b/test/test.js
index a409693..d05ab00 100644
--- a/test/test.js
+++ b/test/test.js
@@ -1,10 +1,11 @@
-var FdSlicer = require('../');
+var fdSlicer = require('../');
var fs = require('fs');
var crypto = require('crypto');
var path = require('path');
var streamEqual = require('stream-equal');
var assert = require('assert');
var Pend = require('pend');
+var StreamSink = require('streamsink');
var describe = global.describe;
var it = global.it;
@@ -41,13 +42,13 @@ describe("FdSlicer", function() {
it("reads a 20MB file (autoClose on)", function(done) {
fs.open(testBlobFile, 'r', function(err, fd) {
if (err) return done(err);
- var fdSlicer = new FdSlicer(fd, {autoClose: true});
- var actualStream = fdSlicer.createReadStream();
+ var slicer = fdSlicer.createFromFd(fd, {autoClose: true});
+ var actualStream = slicer.createReadStream();
var expectedStream = fs.createReadStream(testBlobFile);
var pend = new Pend();
pend.go(function(cb) {
- fdSlicer.on('close', cb);
+ slicer.on('close', cb);
});
pend.go(function(cb) {
streamEqual(expectedStream, actualStream, function(err, equal) {
@@ -62,15 +63,15 @@ describe("FdSlicer", function() {
it("reads 4 chunks simultaneously", function(done) {
fs.open(testBlobFile, 'r', function(err, fd) {
if (err) return done(err);
- var fdSlicer = new FdSlicer(fd);
- var actualPart1 = fdSlicer.createReadStream({start: testBlobFileSize * 0/4, end: testBlobFileSize * 1/4});
- var actualPart2 = fdSlicer.createReadStream({start: testBlobFileSize * 1/4, end: testBlobFileSize * 2/4});
- var actualPart3 = fdSlicer.createReadStream({start: testBlobFileSize * 2/4, end: testBlobFileSize * 3/4});
- var actualPart4 = fdSlicer.createReadStream({start: testBlobFileSize * 3/4, end: testBlobFileSize * 4/4});
- var expectedPart1 = fdSlicer.createReadStream({start: testBlobFileSize * 0/4, end: testBlobFileSize * 1/4});
- var expectedPart2 = fdSlicer.createReadStream({start: testBlobFileSize * 1/4, end: testBlobFileSize * 2/4});
- var expectedPart3 = fdSlicer.createReadStream({start: testBlobFileSize * 2/4, end: testBlobFileSize * 3/4});
- var expectedPart4 = fdSlicer.createReadStream({start: testBlobFileSize * 3/4, end: testBlobFileSize * 4/4});
+ var slicer = fdSlicer.createFromFd(fd);
+ var actualPart1 = slicer.createReadStream({start: testBlobFileSize * 0/4, end: testBlobFileSize * 1/4});
+ var actualPart2 = slicer.createReadStream({start: testBlobFileSize * 1/4, end: testBlobFileSize * 2/4});
+ var actualPart3 = slicer.createReadStream({start: testBlobFileSize * 2/4, end: testBlobFileSize * 3/4});
+ var actualPart4 = slicer.createReadStream({start: testBlobFileSize * 3/4, end: testBlobFileSize * 4/4});
+ var expectedPart1 = slicer.createReadStream({start: testBlobFileSize * 0/4, end: testBlobFileSize * 1/4});
+ var expectedPart2 = slicer.createReadStream({start: testBlobFileSize * 1/4, end: testBlobFileSize * 2/4});
+ var expectedPart3 = slicer.createReadStream({start: testBlobFileSize * 2/4, end: testBlobFileSize * 3/4});
+ var expectedPart4 = slicer.createReadStream({start: testBlobFileSize * 3/4, end: testBlobFileSize * 4/4});
var pend = new Pend();
pend.go(function(cb) {
streamEqual(expectedPart1, actualPart1, function(err, equal) {
@@ -106,11 +107,11 @@ describe("FdSlicer", function() {
it("writes a 20MB file (autoClose on)", function(done) {
fs.open(testOutBlobFile, 'w', function(err, fd) {
if (err) return done(err);
- var fdSlicer = new FdSlicer(fd, {autoClose: true});
- var actualStream = fdSlicer.createWriteStream();
+ var slicer = fdSlicer.createFromFd(fd, {autoClose: true});
+ var actualStream = slicer.createWriteStream();
var inStream = fs.createReadStream(testBlobFile);
- fdSlicer.on('close', function() {
+ slicer.on('close', function() {
var expected = fs.createReadStream(testBlobFile);
var actual = fs.createReadStream(testOutBlobFile);
@@ -127,11 +128,11 @@ describe("FdSlicer", function() {
it("writes 4 chunks simultaneously", function(done) {
fs.open(testOutBlobFile, 'w', function(err, fd) {
if (err) return done(err);
- var fdSlicer = new FdSlicer(fd);
- var actualPart1 = fdSlicer.createWriteStream({start: testBlobFileSize * 0/4});
- var actualPart2 = fdSlicer.createWriteStream({start: testBlobFileSize * 1/4});
- var actualPart3 = fdSlicer.createWriteStream({start: testBlobFileSize * 2/4});
- var actualPart4 = fdSlicer.createWriteStream({start: testBlobFileSize * 3/4});
+ var slicer = fdSlicer.createFromFd(fd);
+ var actualPart1 = slicer.createWriteStream({start: testBlobFileSize * 0/4});
+ var actualPart2 = slicer.createWriteStream({start: testBlobFileSize * 1/4});
+ var actualPart3 = slicer.createWriteStream({start: testBlobFileSize * 2/4});
+ var actualPart4 = slicer.createWriteStream({start: testBlobFileSize * 3/4});
var in1 = fs.createReadStream(testBlobFile, {start: testBlobFileSize * 0/4, end: testBlobFileSize * 1/4});
var in2 = fs.createReadStream(testBlobFile, {start: testBlobFileSize * 1/4, end: testBlobFileSize * 2/4});
var in3 = fs.createReadStream(testBlobFile, {start: testBlobFileSize * 2/4, end: testBlobFileSize * 3/4});
@@ -168,14 +169,25 @@ describe("FdSlicer", function() {
});
});
+ it("throws on invalid ref", function(done) {
+ fs.open(testOutBlobFile, 'w', function(err, fd) {
+ if (err) return done(err);
+ var slicer = fdSlicer.createFromFd(fd, {autoClose: true});
+ assert.throws(function() {
+ slicer.unref();
+ }, /invalid unref/);
+ fs.close(fd, done);
+ });
+ });
+
it("write stream emits error when max size exceeded", function(done) {
fs.open(testOutBlobFile, 'w', function(err, fd) {
if (err) return done(err);
- var fdSlicer = new FdSlicer(fd, {autoClose: true});
- var ws = fdSlicer.createWriteStream({start: 0, end: 1000});
+ var slicer = fdSlicer.createFromFd(fd, {autoClose: true});
+ var ws = slicer.createWriteStream({start: 0, end: 1000});
ws.on('error', function(err) {
assert.strictEqual(err.code, 'ETOOBIG');
- fdSlicer.on('close', done);
+ slicer.on('close', done);
});
ws.end(new Buffer(1001));
});
@@ -184,9 +196,9 @@ describe("FdSlicer", function() {
it("write stream does not emit error when max size not exceeded", function(done) {
fs.open(testOutBlobFile, 'w', function(err, fd) {
if (err) return done(err);
- var fdSlicer = new FdSlicer(fd, {autoClose: true});
- var ws = fdSlicer.createWriteStream({end: 1000});
- fdSlicer.on('close', done);
+ var slicer = fdSlicer.createFromFd(fd, {autoClose: true});
+ var ws = slicer.createWriteStream({end: 1000});
+ slicer.on('close', done);
ws.end(new Buffer(1000));
});
});
@@ -194,11 +206,11 @@ describe("FdSlicer", function() {
it("write stream start and end work together", function(done) {
fs.open(testOutBlobFile, 'w', function(err, fd) {
if (err) return done(err);
- var fdSlicer = new FdSlicer(fd, {autoClose: true});
- var ws = fdSlicer.createWriteStream({start: 1, end: 1000});
+ var slicer = fdSlicer.createFromFd(fd, {autoClose: true});
+ var ws = slicer.createWriteStream({start: 1, end: 1000});
ws.on('error', function(err) {
assert.strictEqual(err.code, 'ETOOBIG');
- fdSlicer.on('close', done);
+ slicer.on('close', done);
});
ws.end(new Buffer(1000));
});
@@ -207,8 +219,8 @@ describe("FdSlicer", function() {
it("write stream emits progress events", function(done) {
fs.open(testOutBlobFile, 'w', function(err, fd) {
if (err) return done(err);
- var fdSlicer = new FdSlicer(fd, {autoClose: true});
- var ws = fdSlicer.createWriteStream();
+ var slicer = fdSlicer.createFromFd(fd, {autoClose: true});
+ var ws = slicer.createWriteStream();
var progressEventCount = 0;
var prevBytesWritten = 0;
ws.on('progress', function() {
@@ -216,7 +228,7 @@ describe("FdSlicer", function() {
assert.ok(ws.bytesWritten > prevBytesWritten);
prevBytesWritten = ws.bytesWritten;
});
- fdSlicer.on('close', function() {
+ slicer.on('close', function() {
assert.ok(progressEventCount > 5);
done();
});
@@ -230,9 +242,9 @@ describe("FdSlicer", function() {
it("write stream unrefs when destroyed", function(done) {
fs.open(testOutBlobFile, 'w', function(err, fd) {
if (err) return done(err);
- var fdSlicer = new FdSlicer(fd, {autoClose: true});
- var ws = fdSlicer.createWriteStream();
- fdSlicer.on('close', done);
+ var slicer = fdSlicer.createFromFd(fd, {autoClose: true});
+ var ws = slicer.createWriteStream();
+ slicer.on('close', done);
ws.write(new Buffer(1000));
ws.destroy();
});
@@ -241,13 +253,98 @@ describe("FdSlicer", function() {
it("read stream unrefs when destroyed", function(done) {
fs.open(testBlobFile, 'r', function(err, fd) {
if (err) return done(err);
- var fdSlicer = new FdSlicer(fd, {autoClose: true});
- var rs = fdSlicer.createReadStream();
+ var slicer = fdSlicer.createFromFd(fd, {autoClose: true});
+ var rs = slicer.createReadStream();
rs.on('error', function(err) {
assert.strictEqual(err.message, "stream destroyed");
- fdSlicer.on('close', done);
+ slicer.on('close', done);
});
rs.destroy();
});
});
+
+ it("fdSlicer.read", function(done) {
+ fs.open(testBlobFile, 'r', function(err, fd) {
+ if (err) return done(err);
+ var slicer = fdSlicer.createFromFd(fd);
+ var outBuf = new Buffer(1024);
+ slicer.read(outBuf, 0, 10, 0, function(err, bytesRead, buf) {
+ assert.strictEqual(bytesRead, 10);
+ fs.close(fd, done);
+ });
+ });
+ });
+
+ it("fdSlicer.write", function(done) {
+ fs.open(testOutBlobFile, 'w', function(err, fd) {
+ if (err) return done(err);
+ var slicer = fdSlicer.createFromFd(fd);
+ slicer.write(new Buffer("blah\n"), 0, 5, 0, function() {
+ if (err) return done(err);
+ fs.close(fd, done);
+ });
+ });
+ });
+});
+
+describe("BufferSlicer", function() {
+ it("invalid ref", function() {
+ var slicer = fdSlicer.createFromBuffer(new Buffer(16));
+ slicer.ref();
+ slicer.unref();
+ assert.throws(function() {
+ slicer.unref();
+ }, /invalid unref/);
+ });
+ it("read and write", function(done) {
+ var buf = new Buffer("through the tangled thread the needle finds its way");
+ var slicer = fdSlicer.createFromBuffer(buf);
+ var outBuf = new Buffer(1024);
+ slicer.read(outBuf, 10, 11, 8, function(err) {
+ if (err) return done(err);
+ assert.strictEqual(outBuf.toString('utf8', 10, 21), "the tangled");
+ slicer.write(new Buffer("derp"), 0, 4, 7, function(err) {
+ if (err) return done(err);
+ assert.strictEqual(buf.toString('utf8', 7, 19), "derp tangled");
+ done();
+ });
+ });
+ });
+ it("createReadStream", function(done) {
+ var str = "I never conquered rarely came, 16 just held such better days";
+ var buf = new Buffer(str);
+ var slicer = fdSlicer.createFromBuffer(buf);
+ var inStream = slicer.createReadStream();
+ var sink = new StreamSink();
+ inStream.pipe(sink);
+ sink.on('finish', function() {
+ assert.strictEqual(sink.toString(), str);
+ inStream.destroy();
+ done();
+ });
+ });
+ it("createWriteStream exceed buffer size", function(done) {
+ var slicer = fdSlicer.createFromBuffer(new Buffer(4));
+ var outStream = slicer.createWriteStream();
+ outStream.on('error', function(err) {
+ assert.strictEqual(err.code, 'ETOOBIG');
+ done();
+ });
+ outStream.write("hi!\n");
+ outStream.write("it warked\n");
+ outStream.end();
+ });
+ it("createWriteStream ok", function(done) {
+ var buf = new Buffer(1024);
+ var slicer = fdSlicer.createFromBuffer(buf);
+ var outStream = slicer.createWriteStream();
+ outStream.on('finish', function() {
+ assert.strictEqual(buf.toString('utf8', 0, "hi!\nit warked\n".length), "hi!\nit warked\n");
+ outStream.destroy();
+ done();
+ });
+ outStream.write("hi!\n");
+ outStream.write("it warked\n");
+ outStream.end();
+ });
});
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-fd-slicer.git
More information about the Pkg-javascript-commits
mailing list