Comparing version 0.0.1 to 0.0.2
@@ -49,6 +49,5 @@ var fs = require('fs'); | ||
} | ||
var buffer = new Buffer(toRead); | ||
self.context.pend.go(function(cb) { | ||
if (self.destroyed) return cb(); | ||
var buffer = new Buffer(toRead); | ||
fs.read(self.context.fd, buffer, 0, toRead, self.pos, function(err, bytesRead) { | ||
@@ -55,0 +54,0 @@ if (err) { |
{ | ||
"name": "fd-slicer", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "safely create multiple ReadStream or WriteStream objects from the same file descriptor", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -51,1 +51,42 @@ # fd-slicer | ||
``` | ||
## API Documentation | ||
### FdSlicer | ||
```js | ||
var FdSlicer = require('fd-slicer'); | ||
fs.open("file.txt", 'r', function(err, fd) { | ||
if (err) throw err; | ||
var fdSlicer = new FdSlicer(fd); | ||
// ... | ||
}); | ||
``` | ||
Make sure `fd` is a properly initialized file descriptor. If you want to | ||
use `createReadStream` make sure you open it for reading and if you want | ||
to use `createWriteStream` make sure you open it for writing. | ||
#### Properties | ||
##### fd | ||
The file descriptor passed in. | ||
#### Methods | ||
##### createReadStream(options) | ||
Creates a read stream based on the file descriptor. Passes `options` to | ||
the `Readable` stream constructor. Accepts `start` and `end` options just | ||
like `fs.createReadStream`. | ||
The stream that this returns supports `destroy()` to cancel it. | ||
##### createWriteStream(options) | ||
Creates a write stream based on the file descriptor. Passes `options` to | ||
the `Writable` stream constructor. Accepts the `start` option just | ||
like `fs.createWriteStream`. | ||
The stream that this returns supports `destroy()` to cancel it. |
13330
7
92