https://github.com/seangarner/node-truncate-stream
Node stream which truncates input after N bytes
https://github.com/seangarner/node-truncate-stream
javascript node-streams nodejs stream
Last synced: 2 months ago
JSON representation
Node stream which truncates input after N bytes
- Host: GitHub
- URL: https://github.com/seangarner/node-truncate-stream
- Owner: seangarner
- License: mit
- Created: 2014-11-12T17:25:08.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2016-10-24T16:16:08.000Z (over 8 years ago)
- Last Synced: 2025-03-23T20:37:47.161Z (3 months ago)
- Topics: javascript, node-streams, nodejs, stream
- Language: JavaScript
- Size: 3.91 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# truncate-stream
A Transform stream which truncates input after N bytes. **Warning** since it truncates at a byte
marker it could corrupt the last char of a text stream with doublebyte chars.```
npm install truncate-stream
```When the threshold has been reached it forcibly ends the stream rather than just ignoring any
further bytes. That works for the use case I had but could potentially cause socket hangup errors
with http streams.## Usage
Get 1KB of randomness from randstream which otherwise would continue indefinitely.
```
var RandStream = require('randstream');
var concat = require('concat-stream');
var TruncateStream = require('truncate-stream');var random = new RandStream();
var truncate = new TruncateStream({maxBytes: 1024});random.pipe(truncate).pipe(concat(function(data) {
// data.length === 1024
});
```## Licence
MIT