93 lines
8.9 KiB
JSON
93 lines
8.9 KiB
JSON
{
|
|
"_args": [
|
|
[
|
|
{
|
|
"raw": "stream-buffers@~2.2.0",
|
|
"scope": null,
|
|
"escapedName": "stream-buffers",
|
|
"name": "stream-buffers",
|
|
"rawSpec": "~2.2.0",
|
|
"spec": ">=2.2.0 <2.3.0",
|
|
"type": "range"
|
|
},
|
|
"/home/jdaugherty/work/GT2/GT2-Android/node_modules/bplist-creator"
|
|
]
|
|
],
|
|
"_from": "stream-buffers@>=2.2.0 <2.3.0",
|
|
"_id": "stream-buffers@2.2.0",
|
|
"_inCache": true,
|
|
"_location": "/stream-buffers",
|
|
"_nodeVersion": "0.12.5",
|
|
"_npmUser": {
|
|
"name": "samcday",
|
|
"email": "me@samcday.com.au"
|
|
},
|
|
"_npmVersion": "2.11.2",
|
|
"_phantomChildren": {},
|
|
"_requested": {
|
|
"raw": "stream-buffers@~2.2.0",
|
|
"scope": null,
|
|
"escapedName": "stream-buffers",
|
|
"name": "stream-buffers",
|
|
"rawSpec": "~2.2.0",
|
|
"spec": ">=2.2.0 <2.3.0",
|
|
"type": "range"
|
|
},
|
|
"_requiredBy": [
|
|
"/bplist-creator"
|
|
],
|
|
"_resolved": "https://registry.npmjs.org/stream-buffers/-/stream-buffers-2.2.0.tgz",
|
|
"_shasum": "91d5f5130d1cef96dcfa7f726945188741d09ee4",
|
|
"_shrinkwrap": null,
|
|
"_spec": "stream-buffers@~2.2.0",
|
|
"_where": "/home/jdaugherty/work/GT2/GT2-Android/node_modules/bplist-creator",
|
|
"author": {
|
|
"name": "Sam Day",
|
|
"email": "me@samcday.com.au"
|
|
},
|
|
"bugs": {
|
|
"url": "https://github.com/samcday/node-stream-buffer/issues"
|
|
},
|
|
"dependencies": {},
|
|
"description": "Buffer-backed Streams for reading and writing.",
|
|
"devDependencies": {
|
|
"istanbul": "~0.3.2",
|
|
"vows": ">= 0.5.6"
|
|
},
|
|
"directories": {},
|
|
"dist": {
|
|
"shasum": "91d5f5130d1cef96dcfa7f726945188741d09ee4",
|
|
"tarball": "https://registry.npmjs.org/stream-buffers/-/stream-buffers-2.2.0.tgz"
|
|
},
|
|
"engines": {
|
|
"node": ">= 0.10.0"
|
|
},
|
|
"gitHead": "17024f70e0107175ede0ebcfbe9de7102d8be25f",
|
|
"homepage": "https://github.com/samcday/node-stream-buffer#readme",
|
|
"keywords": [
|
|
"memory streams",
|
|
"streams",
|
|
"buffer streams"
|
|
],
|
|
"license": "Unlicense",
|
|
"main": "./lib/streambuffer.js",
|
|
"maintainers": [
|
|
{
|
|
"name": "samcday",
|
|
"email": "sam.c.day@gmail.com"
|
|
}
|
|
],
|
|
"name": "stream-buffers",
|
|
"optionalDependencies": {},
|
|
"readme": "# Node Stream Buffers\r\n\r\n[![Build Status][badge-travis-img]][badge-travis-url]\r\n[![Code Climate][badge-climate-img]][badge-climate-url]\r\n[![Code Coverage][badge-coverage-img]][badge-coverage-url]\r\n\r\nSimple Readable and Writable Streams that use a [Buffer][node-buffer-docs] to store received data, or for data to send out. Useful for test code, debugging, and a wide range of other utilities.\r\n\r\n## Installation\r\n\r\n[![NPM][badge-npm-img]][badge-npm-url]\r\n\r\n## Usage\r\n\r\nTo use the stream buffers in your module, simply import it and away you go.\r\n\r\n```js\r\nvar streamBuffers = require(\"stream-buffers\");\r\n```\r\n\r\n### Writable StreamBuffer\r\n\r\nWritable Stream Buffers implement the standardized writable stream interface. All write()'s to this object will accumulate in an internal Buffer. If the Buffer overflows it will be resized larger automatically. The initial size of the Buffer and the amount in which it grows can be configured in the constructor.\r\n\r\n```js\r\nvar myWritableStreamBuffer = new streamBuffers.WritableStreamBuffer({\r\n\tinitialSize: (100 * 1024),\t\t// start as 100 kilobytes.\r\n\tincrementAmount: (10 * 1024)\t// grow by 10 kilobytes each time buffer overflows.\r\n});\r\n```\r\n\r\nThe default initial size and increment amount are stored in the following constants:\r\n\r\n```js\r\nstreamBuffers.DEFAULT_INITIAL_SIZE \t\t// (8 * 1024)\r\nstreamBuffers.DEFAULT_INCREMENT_AMOUNT\t// (8 * 1024)\r\n```\r\n\r\nWriting is standard Stream stuff:\r\n\r\n```js\r\nmyWritableStreamBuffer.write(myBuffer);\r\n// - or -\r\nmyWritableStreamBuffer.write(\"\\u00bd + \\u00bc = \\u00be\", \"utf8\");\r\n```\r\n\r\nYou can query the size of the data being held in the Buffer, and also how big the Buffer's max capacity currently is: \r\n\r\n```js\r\nmyWritableStreamBuffer.write(\"ASDF\");\r\nstreamBuffers.size();\t\t\t// 4.\r\nstreamBuffers.maxSize();\t\t// Whatever was configured as initial size. In our example: (100 * 1024).\r\n```\r\n\r\nRetrieving the contents of the Buffer is simple:\r\n\r\n```js\r\nmyWritableStreamBuffer.getContents();\t\t\t\t\t// Gets all held data as a Buffer.\r\nmyWritableStreamBuffer.getContentsAsString(\"utf8\");\t\t// Gets all held data as a utf8 string.\r\nmyWritableStreamBuffer.getContents(5);\t\t\t\t\t// Gets first 5 bytes as a Buffer.\r\nmyWritableStreamBuffer.getContentsAsString(\"utf8\", 5);\t// Gets first 5 bytes as a utf8 string.\r\n```\r\n\r\nCare should be taken when getting encoded strings from WritableStream, as it doesn't really care about the contents (multi-byte characters will not be respected).\r\n \r\nDestroying or ending the WritableStream will not delete the contents of Buffer, but will disallow any further writes:\r\n\r\n```js\r\nmyWritableStreamBuffer.write(\"ASDF\");\r\nmyWritableStreamBuffer.destroy();\r\n\r\nmyWritableStreamBuffer.getContents();\t\t// Returns ASDF in Buffer.\r\nmyWritableStreamBuffer.write(\"Yeah?\");\t\t// No effect.\r\n```\t\r\n\r\n### Readable StreamBuffer\r\n\r\nReadable Stream Buffers can have data inserted in them, which will then be pumped out via standard readable stream data events. The data to be sent out is held in a Buffer, which can grow in much the same way as a WritableStream Buffer does, if data is being put in Buffer faster than it's being pumped out. \r\n\r\nThe frequency in which chunks are pumped out, and the size of the chunks themselves can be configured in the constructor. The initial size and increment amount of internal Buffer can be configured too.\r\n\r\n```js\r\nvar myReadableStreamBuffer = new streamBuffers.ReadableStreamBuffer({\r\n\tfrequency: 10,\t\t// in milliseconds.\r\n\tchunkSize: 2048\t\t// in bytes.\r\n});\r\n```\r\n\r\nDefault frequency and chunk size:\r\n\r\n```js\r\nstreamBuffers.DEFAULT_CHUNK_SIZE \t\t// (1024)\r\nstreamBuffers.DEFAULT_FREQUENCY\t\t\t// (1)\r\n```\r\n\r\nPutting data in Buffer to be pumped out is easy:\r\n\r\n```js\r\nmyReadableStreamBuffer.put(aBuffer);\r\nmyReadableStreamBuffer.put(\"A String\", \"utf8\");\r\n```\r\n\r\nChunks are pumped out via standard readable stream spec: \r\n\r\n```js\r\nmyReadableStreamBuffer.on(\"data\", function(data) {\r\n\t// Yup.\r\n\tassert.isTrue(data instanceof Buffer);\r\n});\r\n```\r\n\r\nChunks are pumped out by the interval that you specified in frequency. Setting the frequency to 0 will immediately stream the data (also in chunks), even if the stream has not been piped to a destination. This is useful for unit testing. \r\n\r\nsetEncoding() for streams is respected too:\r\n\r\n```js\r\nmyReadableStreamBuffer.setEncoding(\"utf8\");\r\nmyReadableStreamBuffer.on(\"data\", function(data) {\r\n\tassert.isTrue(data instanceof String);\r\n});\r\n```\r\n\r\nPause and resume are also implemented. pause()'ing stream will allow buffer to continue accumulating, but will not pump any of that data out until it is resume()'d again. \r\n\r\nDestroying the stream will immediately purge the buffer, unless destroySoon() is called, in which case the rest of the buffer will be written out. Either way, any further attempts to put data in the Buffer will be silently ignored. \r\n\r\n```js\r\nmyReadableStreamBuffer.destroySoon();\r\nmyReadableStreamBuffer.put(\"A String!\");\r\nmyReadableStreamBuffer.size();\t\t\t// will be 0.\r\n```\r\n\r\n## Disclaimer\r\n\r\nNot supposed to be a speed demon, it's more for tests/debugging or weird edge cases. It works with an internal buffer that it copies contents to/from/around.\r\n\r\n## Contributors\r\n\r\nThanks to the following people for taking some time to contribute to this project.\r\n\r\n * Igor Dralyuk <idralyuk@ebay.com>\r\n * Simon Koudijs <simon.koudijs@intellifi.nl>\r\n\r\n## License\r\n\r\nnode-stream-buffer is free and unencumbered public domain software. For more information, see the accompanying UNLICENSE file.\r\n\r\n[badge-travis-img]: http://img.shields.io/travis/samcday/node-stream-buffer.svg?style=flat-square\r\n[badge-travis-url]: https://travis-ci.org/samcday/node-stream-buffer\r\n[badge-climate-img]: http://img.shields.io/codeclimate/github/samcday/node-stream-buffer.svg?style=flat-square\r\n[badge-climate-url]: https://codeclimate.com/github/samcday/node-stream-buffer\r\n[badge-coverage-img]: http://img.shields.io/codeclimate/coverage/github/samcday/node-stream-buffer.svg?style=flat-square\r\n[badge-coverage-url]: https://codeclimate.com/github/samcday/node-stream-buffer\r\n[badge-npm-img]: https://nodei.co/npm/stream-buffers.png?downloads=true&downloadRank=true&stars=true\r\n[badge-npm-url]: https://npmjs.org/package/stream-buffers\r\n\r\n[node-buffer-docs]: http://nodejs.org/api/buffer.html\r\n",
|
|
"readmeFilename": "README.md",
|
|
"repository": {
|
|
"type": "git",
|
|
"url": "git+https://github.com/samcday/node-stream-buffer.git"
|
|
},
|
|
"scripts": {
|
|
"test": "[ -n \"$NO_COVERAGE\" ] && vows --spec || istanbul cover vows -- --spec"
|
|
},
|
|
"version": "2.2.0"
|
|
}
|