pax_global_header00006660000000000000000000000064125644007170014520gustar00rootroot0000000000000052 comment=55cd41dd1ff020282b2e9fe47620e71838d29646 gzip-size-3.0.0/000077500000000000000000000000001256440071700134415ustar00rootroot00000000000000gzip-size-3.0.0/.editorconfig000066400000000000000000000003471256440071700161220ustar00rootroot00000000000000root = true [*] indent_style = tab end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true [{package.json,*.yml}] indent_style = space indent_size = 2 [*.md] trim_trailing_whitespace = false gzip-size-3.0.0/.gitattributes000066400000000000000000000000141256440071700163270ustar00rootroot00000000000000* text=auto gzip-size-3.0.0/.gitignore000066400000000000000000000000151256440071700154250ustar00rootroot00000000000000node_modules gzip-size-3.0.0/.travis.yml000066400000000000000000000000751256440071700155540ustar00rootroot00000000000000sudo: false language: node_js node_js: - 'iojs' - '0.12' gzip-size-3.0.0/index.js000066400000000000000000000016671256440071700151200ustar00rootroot00000000000000'use strict'; var duplexer = require('duplexer'); var stream = require('stream'); var zlib = require('zlib'); var opts = {level: 9}; module.exports = function (str, cb) { if (!str) { cb(null, 0); return; } zlib.gzip(str, opts, function (err, data) { if (err) { cb(err, 0); return; } cb(err, data.length); }); }; module.exports.sync = function (str) { return zlib.gzipSync(str, opts).length; }; module.exports.stream = function () { var input = new stream.PassThrough(); var output = new stream.PassThrough(); var wrapper = duplexer(input, output); var gzipSize = 0; var gzip = zlib.createGzip(opts) .on('data', function (buf) { gzipSize += buf.length; }) .on('error', function () { wrapper.gzipSize = 0; }) .on('end', function () { wrapper.gzipSize = gzipSize; wrapper.emit('gzip-size', gzipSize); output.end(); }); input.pipe(gzip); input.pipe(output, {end: false}); return wrapper; }; gzip-size-3.0.0/license000066400000000000000000000021371256440071700150110ustar00rootroot00000000000000The MIT License (MIT) Copyright (c) Sindre Sorhus (sindresorhus.com) 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. gzip-size-3.0.0/package.json000066400000000000000000000012201256440071700157220ustar00rootroot00000000000000{ "name": "gzip-size", "version": "3.0.0", "description": "Get the gzipped size of a string or buffer", "license": "MIT", "repository": "sindresorhus/gzip-size", "author": { "name": "Sindre Sorhus", "email": "sindresorhus@gmail.com", "url": "sindresorhus.com" }, "engines": { "node": ">=0.12.0" }, "scripts": { "test": "xo && tap test.js" }, "files": [ "index.js" ], "keywords": [ "app", "tool", "zlib", "gzip", "compressed", "size", "string", "buffer" ], "dependencies": { "duplexer": "^0.1.1" }, "devDependencies": { "tap": "^1.3.2", "xo": "*" } } gzip-size-3.0.0/readme.md000066400000000000000000000017771256440071700152340ustar00rootroot00000000000000# gzip-size [![Build Status](https://travis-ci.org/sindresorhus/gzip-size.svg?branch=master)](https://travis-ci.org/sindresorhus/gzip-size) > Get the gzipped size of a string or buffer ## Install ``` $ npm install --save gzip-size ``` ## Usage ```js var gzipSize = require('gzip-size'); var string = 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.'; console.log(string.length); //=> 191 console.log(gzipSize.sync(string)); //=> 78 ``` ## API ### gzipSize(input, callback) ### gzipSize.sync(input) #### input Type: `string`, `buffer` #### callback(error, size) Type: `function` ### gzipSize.stream() Returns a passthrough stream. The stream emits a `gzip-size` event and has a `gzipSize` property. ## Related - [gzip-size-cli](https://github.com/sindresorhus/gzip-size-cli) - CLI for this module ## License MIT © [Sindre Sorhus](http://sindresorhus.com) gzip-size-3.0.0/test.js000066400000000000000000000022561256440071700147630ustar00rootroot00000000000000'use strict'; var fs = require('fs'); var tap = require('tap'); var gzipSize = require('./'); var a = fs.readFileSync('test.js', 'utf8'); tap.test('get the gzipped size', function (t) { t.plan(2); gzipSize(a, function (err, size) { t.assert(!err); t.assert(size < a.length); }); }); tap.test('sync - get the gzipped size', function (t) { t.plan(1); t.assert(gzipSize.sync(a) < a.length); }); tap.test('sync - match async version', function (t) { t.plan(2); gzipSize(a, function (err, size) { t.assert(!err); t.assert(gzipSize.sync(a) === size); }); }); tap.test('stream', function (t) { t.plan(1); fs.createReadStream('test.js') .pipe(gzipSize.stream()) .on('end', function () { t.equal(this.gzipSize, gzipSize.sync(a)); }); }); tap.test('gzip-size event', function (t) { t.plan(1); fs.createReadStream('test.js') .pipe(gzipSize.stream()) .on('gzip-size', function (size) { t.equal(size, gzipSize.sync(a)); }); }); tap.test('passthrough', function (t) { t.plan(1); var out = ''; fs.createReadStream('test.js') .pipe(gzipSize.stream()) .on('data', function (buf) { out += buf; }) .on('end', function () { t.equal(out, a); }); });