pax_global_header00006660000000000000000000000064125674160130014517gustar00rootroot0000000000000052 comment=a448c573805056a9aca57acbc2e68b65665b5f58 quote-stream-1.0.2/000077500000000000000000000000001256741601300141455ustar00rootroot00000000000000quote-stream-1.0.2/.travis.yml000066400000000000000000000000601256741601300162520ustar00rootroot00000000000000language: node_js node_js: - "0.8" - "0.10" quote-stream-1.0.2/LICENSE000066400000000000000000000020611256741601300151510ustar00rootroot00000000000000This software is released under the MIT license: 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. quote-stream-1.0.2/bin/000077500000000000000000000000001256741601300147155ustar00rootroot00000000000000quote-stream-1.0.2/bin/cmd.js000077500000000000000000000005301256741601300160170ustar00rootroot00000000000000#!/usr/bin/env node var quote = require('../'); var minimist = require('minimist'); var fs = require('fs'); var argv = minimist(process.argv.slice(2), { alias: { h: 'help' } }); if (argv.help) { var s = fs.createReadStream(__dirname + '/usage.txt'); return s.pipe(process.stdout); } process.stdin.pipe(quote()).pipe(process.stdout); quote-stream-1.0.2/bin/usage.txt000066400000000000000000000001061256741601300165570ustar00rootroot00000000000000usage: quote-stream Transform stdin to a quoted string on stdout. quote-stream-1.0.2/example/000077500000000000000000000000001256741601300156005ustar00rootroot00000000000000quote-stream-1.0.2/example/stream.js000066400000000000000000000001161256741601300174270ustar00rootroot00000000000000var quote = require('../'); process.stdin.pipe(quote()).pipe(process.stdout); quote-stream-1.0.2/index.js000066400000000000000000000056411256741601300156200ustar00rootroot00000000000000var through = require('through2'); var equals = require('buffer-equal') var buffers = { quote: Buffer('"'), escapeQuote: Buffer('\\"'), escapeEscape: Buffer('\\\\'), escapeB: Buffer('\\b'), escapeF: Buffer('\\f'), escapeN: Buffer('\\n'), escapeR: Buffer('\\r'), escapeT: Buffer('\\t'), escapeLineSeparator: Buffer('\\u2028'), escapeParagraphSeparator: Buffer('\\u2029') }; for (var i = 0; i < 32; i++) { var s = i.toString(16); buffers[i] = Buffer('\\u' + Array(5-s.length).join('0') + s); } var codes = { quote: '"'.charCodeAt(0), escape: '\\'.charCodeAt(0), b: '\b'.charCodeAt(0), f: '\f'.charCodeAt(0), n: '\n'.charCodeAt(0), r: '\r'.charCodeAt(0), t: '\t'.charCodeAt(0) }; var multiByteBuffers = { lineSeparator: Buffer('\u2028', 'utf8'), paragraphSeparator: Buffer('\u2029', 'utf8') }; var multiByteSeparatorLength = multiByteBuffers.lineSeparator.length; // same for both var multiByteSeparatorOffset = multiByteSeparatorLength - 1; var multiByteSeparatorCode = multiByteBuffers.lineSeparator[0]; // same for both var map = {}; map[codes.quote] = buffers.escapeQuote; map[codes.escape] = buffers.escapeEscape; map[codes.b] = buffers.escapeB; map[codes.f] = buffers.escapeF; map[codes.n] = buffers.escapeN; map[codes.r] = buffers.escapeR; map[codes.t] = buffers.escapeT; module.exports = function () { var stream = through(write, end); stream.push(buffers.quote); return stream; function write (buf, enc, next) { var offset = 0; for (var i = 0; i < buf.length; i++) { var c = buf[i]; var m = map[c]; if (m) { var bufs = [ buf.slice(offset, i), m ]; this.push(Buffer.concat(bufs)); offset = i + 1; } else if (c < 32) { var bufs = [ buf.slice(offset, i), buffers[c] ]; this.push(Buffer.concat(bufs)); offset = i + 1; } else if (c === multiByteSeparatorCode) { var rawBuf = buf.slice(i, i + multiByteSeparatorLength); var escapeBuf = null; if (equals(rawBuf, multiByteBuffers.lineSeparator)) { escapeBuf = buffers.escapeLineSeparator; } else if (equals(rawBuf, multiByteBuffers.paragraphSeparator)) { escapeBuf = buffers.escapeParagraphSeparator; } if (escapeBuf) { var bufs = [ buf.slice(offset, i), escapeBuf ]; this.push(Buffer.concat(bufs)); offset = i + multiByteSeparatorLength; i += multiByteSeparatorOffset } } } if (offset === 0) this.push(buf) else this.push(buf.slice(offset)); next(); } function end (next) { this.push(buffers.quote); this.push(null); } }; quote-stream-1.0.2/package.json000066400000000000000000000022131256741601300164310ustar00rootroot00000000000000{ "name": "quote-stream", "version": "1.0.2", "description": "transform a stream into a quoted string", "main": "index.js", "bin": { "quote-stream": "bin/cmd.js" }, "dependencies": { "buffer-equal": "0.0.1", "minimist": "^1.1.3", "through2": "^2.0.0" }, "devDependencies": { "concat-stream": "~1.4.5", "tape": "^4.1.0" }, "scripts": { "test": "tape test/*.js" }, "repository": { "type": "git", "url": "git://github.com/substack/quote-stream.git" }, "homepage": "https://github.com/substack/quote-stream", "keywords": [ "quote", "transform", "stream" ], "author": { "name": "James Halliday", "email": "mail@substack.net", "url": "http://substack.net" }, "license": "MIT", "testling": { "files": "test/*.js", "browsers": [ "ie/8..latest", "firefox/15", "firefox/latest", "firefox/nightly", "chrome/15", "chrome/latest", "chrome/canary", "opera/12..latest", "opera/next", "safari/5.1..latest", "ipad/6.0..latest", "iphone/6.0..latest", "android-browser/4.2..latest" ] } } quote-stream-1.0.2/readme.markdown000066400000000000000000000015201256741601300171440ustar00rootroot00000000000000# quote-stream transform a stream into a quoted string [![testling badge](https://ci.testling.com/substack/quote-stream.png)](https://ci.testling.com/substack/quote-stream) [![build status](https://secure.travis-ci.org/substack/quote-stream.png)](http://travis-ci.org/substack/quote-stream) # example ``` js var quote = require('quote-stream'); process.stdin.pipe(quote()).pipe(process.stdout); ``` output: ``` $ echo beep boop | node example/stream.js "beep boop\n" ``` # methods ``` js var quote = require('quote-stream') ``` ## var q = quote() Return a transform stream `q` that wraps input in double quotes and adds escape characters to the chunks. # usage ``` usage: quote-stream Transform stdin to a quoted string on stdout. ``` # install With [npm](https://npmjs.org) do: ``` npm install quote-stream ``` # license MIT quote-stream-1.0.2/test/000077500000000000000000000000001256741601300151245ustar00rootroot00000000000000quote-stream-1.0.2/test/simple.js000066400000000000000000000004331256741601300167530ustar00rootroot00000000000000var quote = require('../'); var concat = require('concat-stream'); var test = require('tape'); test('simple', function (t) { t.plan(1); var q = quote(); q.end('abc'); q.pipe(concat(function (body) { t.equal(body.toString('utf8'), '"abc"'); })); }); quote-stream-1.0.2/test/unicode_separators.js000066400000000000000000000011521256741601300213520ustar00rootroot00000000000000var quote = require('../'); var concat = require('concat-stream'); var test = require('tape'); test('js string unicode separators', function (t) { t.plan(1); var q = quote(); q.end('\u2027beep\u2028ima\u2029jeep\u2030'); q.pipe(concat(function (body) { t.equal(body.toString('utf8'), '"\u2027beep\\u2028ima\\u2029jeep\u2030"'); })); }); test('utf8 separators', function (t) { t.plan(1); var q = quote(); q.end(Buffer('beep\u2028ima\u2029jeep', 'utf8')); q.pipe(concat(function (body) { t.equal(body.toString('utf8'), '"beep\\u2028ima\\u2029jeep"'); })); }); quote-stream-1.0.2/test/whitespace.js000066400000000000000000000004771256741601300176260ustar00rootroot00000000000000var quote = require('../'); var concat = require('concat-stream'); var test = require('tape'); test('whitespace', function (t) { t.plan(1); var q = quote(); q.end('abc\ndef\tghi\r\n'); q.pipe(concat(function (body) { t.equal(body.toString('utf8'), '"abc\\ndef\\tghi\\r\\n"'); })); });