Full Code of sindresorhus/gzip-size-cli for AI

main 73c47861635f cached
10 files
5.7 KB
1.9k tokens
1 symbols
1 requests
Download .txt
Repository: sindresorhus/gzip-size-cli
Branch: main
Commit: 73c47861635f
Files: 10
Total size: 5.7 KB

Directory structure:
gitextract_l8aaff6o/

├── .editorconfig
├── .gitattributes
├── .github/
│   └── workflows/
│       └── main.yml
├── .gitignore
├── .npmrc
├── cli.js
├── license
├── package.json
├── readme.md
└── test.js

================================================
FILE CONTENTS
================================================

================================================
FILE: .editorconfig
================================================
root = true

[*]
indent_style = tab
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.yml]
indent_style = space
indent_size = 2


================================================
FILE: .gitattributes
================================================
* text=auto eol=lf


================================================
FILE: .github/workflows/main.yml
================================================
name: CI
on:
  - push
  - pull_request
jobs:
  test:
    name: Node.js ${{ matrix.node-version }}
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        node-version:
          - 16
          - 14
          - 12
    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-node@v2
        with:
          node-version: ${{ matrix.node-version }}
      - run: npm install
      - run: npm test


================================================
FILE: .gitignore
================================================
node_modules
yarn.lock


================================================
FILE: .npmrc
================================================
package-lock=false


================================================
FILE: cli.js
================================================
#!/usr/bin/env node
import process from 'node:process';
import fs from 'node:fs';
import meow from 'meow';
import prettyBytes from 'pretty-bytes';
import {gzipSizeSync} from 'gzip-size';
import chalk from 'chalk';
import getStdin from 'get-stdin';

const cli = meow(`
	Usage
	  $ gzip-size <file>
	  $ cat <file> | gzip-size

	Options
	  --level             Compression level [0-9] (Default: 9)
	  --raw               Display value in bytes
	  --include-original  Include original size

	Examples
	  $ gzip-size unicorn.png
	  192 kB
	  $ gzip-size unicorn.png --raw
	  192256
	  $ gzip-size unicorn.png --include-original
	  392 kB → 192 kB
`, {
	importMeta: import.meta,
	flags: {
		level: {
			type: 'number',
		},
		raw: {
			type: 'boolean',
		},
		includeOriginal: {
			type: 'boolean',
		},
	},
});

const [input] = cli.input;

if (!input && process.stdin.isTTY) {
	console.error('Specify a file path');
	process.exit(1);
}

const options = {};
if (cli.flags.level) {
	options.level = cli.flags.level;
}

function output(data) {
	const originalSize = data.length;
	const gzippedSize = gzipSizeSync(data);

	let output = cli.flags.raw ? gzippedSize : prettyBytes(gzippedSize);
	if (cli.flags.includeOriginal) {
		output = (cli.flags.raw ? originalSize : prettyBytes(originalSize)) + chalk.dim(' → ') + output;
	}

	console.log(output);
}

(async () => {
	if (input) {
		output(fs.readFileSync(input));
	} else {
		output(await getStdin.buffer());
	}
})();


================================================
FILE: license
================================================
MIT License

Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://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.


================================================
FILE: package.json
================================================
{
	"name": "gzip-size-cli",
	"version": "5.1.0",
	"description": "Get the gzipped size of a file or stdin",
	"license": "MIT",
	"repository": "sindresorhus/gzip-size-cli",
	"funding": "https://github.com/sponsors/sindresorhus",
	"author": {
		"name": "Sindre Sorhus",
		"email": "sindresorhus@gmail.com",
		"url": "https://sindresorhus.com"
	},
	"type": "module",
	"bin": {
		"gzip-size": "./cli.js"
	},
	"engines": {
		"node": ">=12"
	},
	"scripts": {
		"test": "xo && ava"
	},
	"files": [
		"cli.js"
	],
	"keywords": [
		"cli-app",
		"cli",
		"zlib",
		"gzip",
		"compressed",
		"size",
		"file",
		"stdin"
	],
	"dependencies": {
		"chalk": "^4.1.2",
		"get-stdin": "^9.0.0",
		"gzip-size": "^7.0.0",
		"meow": "^10.1.2",
		"pretty-bytes": "^5.6.0"
	},
	"devDependencies": {
		"ava": "^3.15.0",
		"execa": "^6.0.0",
		"xo": "^0.46.4"
	}
}


================================================
FILE: readme.md
================================================
# gzip-size-cli

> Get the gzipped size of a file or stdin

## Install

```sh
npm install --global gzip-size-cli
```

## Usage

```
$ gzip-size --help

  Usage
    $ gzip-size <file>
    $ cat <file> | gzip-size

  Options
    --level             Compression level [0-9] (Default: 9)
    --raw               Display value in bytes
    --include-original  Include original size

  Examples
    $ gzip-size unicorn.png
    192 kB
    $ gzip-size unicorn.png --raw
    192256
    $ gzip-size unicorn.png --include-original
    392 kB → 192 kB
```

## Related

- [gzip-size](https://github.com/sindresorhus/gzip-size) - API for this module


================================================
FILE: test.js
================================================
import fs from 'node:fs';
import {execa} from 'execa';
import test from 'ava';
import {gzipSizeSync} from 'gzip-size';

const fixture = fs.readFileSync('test.js', 'utf8');

test('main', async t => {
	const {stdout} = await execa('./cli.js', ['test.js']);
	t.regex(stdout, /^\d+ B$/);
});

test('file', async t => {
	const {stdout} = await execa('./cli.js', ['test.js', '--raw']);
	t.is(Number.parseInt(stdout, 10), gzipSizeSync(fixture));
});

test('stdin', async t => {
	const {stdout} = await execa('./cli.js', ['test.js', '--raw'], {
		input: fs.createReadStream('test.js'),
	});
	t.is(Number.parseInt(stdout, 10), gzipSizeSync(fixture));
});

test('include original', async t => {
	const {stdout} = await execa('./cli.js', ['test.js', '--raw', '--include-original']);
	const {size} = fs.statSync('test.js');
	t.is(Number.parseInt(stdout, 10), size);
});

test('include original - stdin', async t => {
	const {stdout} = await execa('./cli.js', ['--raw', '--include-original'], {
		input: fs.createReadStream('test.js'),
	});
	const {size} = fs.statSync('test.js');
	t.is(Number.parseInt(stdout, 10), size);
});
Download .txt
gitextract_l8aaff6o/

├── .editorconfig
├── .gitattributes
├── .github/
│   └── workflows/
│       └── main.yml
├── .gitignore
├── .npmrc
├── cli.js
├── license
├── package.json
├── readme.md
└── test.js
Download .txt
SYMBOL INDEX (1 symbols across 1 files)

FILE: cli.js
  function output (line 54) | function output(data) {
Condensed preview — 10 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (7K chars).
[
  {
    "path": ".editorconfig",
    "chars": 175,
    "preview": "root = true\n\n[*]\nindent_style = tab\nend_of_line = lf\ncharset = utf-8\ntrim_trailing_whitespace = true\ninsert_final_newlin"
  },
  {
    "path": ".gitattributes",
    "chars": 19,
    "preview": "* text=auto eol=lf\n"
  },
  {
    "path": ".github/workflows/main.yml",
    "chars": 436,
    "preview": "name: CI\non:\n  - push\n  - pull_request\njobs:\n  test:\n    name: Node.js ${{ matrix.node-version }}\n    runs-on: ubuntu-la"
  },
  {
    "path": ".gitignore",
    "chars": 23,
    "preview": "node_modules\nyarn.lock\n"
  },
  {
    "path": ".npmrc",
    "chars": 19,
    "preview": "package-lock=false\n"
  },
  {
    "path": "cli.js",
    "chars": 1462,
    "preview": "#!/usr/bin/env node\nimport process from 'node:process';\nimport fs from 'node:fs';\nimport meow from 'meow';\nimport pretty"
  },
  {
    "path": "license",
    "chars": 1117,
    "preview": "MIT License\n\nCopyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)\n\nPermission is hereby grant"
  },
  {
    "path": "package.json",
    "chars": 841,
    "preview": "{\n\t\"name\": \"gzip-size-cli\",\n\t\"version\": \"5.1.0\",\n\t\"description\": \"Get the gzipped size of a file or stdin\",\n\t\"license\": "
  },
  {
    "path": "readme.md",
    "chars": 636,
    "preview": "# gzip-size-cli\n\n> Get the gzipped size of a file or stdin\n\n## Install\n\n```sh\nnpm install --global gzip-size-cli\n```\n\n##"
  },
  {
    "path": "test.js",
    "chars": 1114,
    "preview": "import fs from 'node:fs';\nimport {execa} from 'execa';\nimport test from 'ava';\nimport {gzipSizeSync} from 'gzip-size';\n\n"
  }
]

About this extraction

This page contains the full source code of the sindresorhus/gzip-size-cli GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 10 files (5.7 KB), approximately 1.9k tokens, and a symbol index with 1 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.

Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.

Copied to clipboard!