Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

gzipper

Package Overview
Dependencies
Maintainers
1
Versions
73
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gzipper - npm Package Compare versions

Comparing version 1.5.1 to 2.0.0

Gzipper.js

1

.eslintrc.js

@@ -6,2 +6,3 @@ module.exports = {

node: true,
jasmine: true,
},

@@ -8,0 +9,0 @@ extends: ['prettier', 'eslint:recommended'],

102

index.js
#!/usr/bin/env node
const zlib = require('zlib')
const fs = require('fs')
const path = require('path')
const program = require('commander')
const version = require('./package.json').version
const Gzipper = require('./Gzipper')
let outputDir
program
.version(version)
.usage('[options] <path>')
.action(folderPath => {
if (!folderPath) {
throw new Error(`Can't find a path.`)
}
outputDir = path.resolve(process.cwd(), folderPath)
})
.usage('[options] <path> [outputPath]')
.option('-v, --verbose', 'detailed level of logs')
.option(
'-gl, --gzip-level',
'gzip compression level 0 (no compression) - 9 (best compression)'
)
.option(
'-gm, --gzip-memory-level',
'amount of memory which will be allocated for compression 1 (minimum memory) - 9 (maximum memory)'
)
.option(
'-gs, --gzip-strategy',
'compression strategy 1 (filtered) - 2 (huffman only) - 3 (RLE) - 4 (fixed)'
)
.parse(process.argv)
let logger = program.verbose ? loggerInit(true) : loggerInit(false)
compileFolderRecursively(outputDir)
/**
* Compile files in folders recursively.
*
* @param {string} outputDir
* @param {number} fileCounter
*/
function compileFolderRecursively(
outputDir,
globalCount = 0,
successGlobalCount = 0
) {
const filesList = fs.readdirSync(outputDir)
try {
filesList.forEach(file => {
const filePath = path.resolve(outputDir, file)
if (
fs.lstatSync(filePath).isFile() &&
(path.extname(filePath) === '.js' || path.extname(filePath) === '.css')
) {
++globalCount
compressFile(file, outputDir, () => {
++successGlobalCount
logger(`File ${file} has been compiled.`)
if (globalCount === successGlobalCount) {
logger(`${globalCount} files have been compiled.`, true)
}
})
} else if (fs.lstatSync(filePath).isDirectory()) {
compileFolderRecursively(filePath, globalCount, successGlobalCount)
}
})
} catch (err) {
console.error(err)
logger(`${globalCount} files have been compiled.`, true)
}
}
/**
* File compression.
*
* @param {string} filename
* @param {string} outputDir
* @param {any} callback
*/
function compressFile(filename, outputDir, callback) {
let compress = zlib.createGzip()
let input = fs.createReadStream(path.join(outputDir, filename))
let output = fs.createWriteStream(`${path.join(outputDir, filename)}.gz`)
input.pipe(compress).pipe(output)
if (callback) {
output.on('finish', callback)
output.on('error', error => console.error(error))
}
}
/**
* Custom logger.
*
* @param {boolean} enable
* @return {Function} logger function
*/
function loggerInit(enable) {
return (message, force) => (enable || force) && console.log(message)
}
const [target, outputPath] = program.args
new Gzipper(target, outputPath, program).compress()
{
"name": "gzipper",
"version": "1.5.1",
"version": "2.0.0",
"description": "CLI for gzipping files.",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"test": "mocha",
"prettier": "prettier --write \"**/*.js\"",

@@ -35,5 +35,9 @@ "eslint": "eslint \"**/*.js\"",

"devDependencies": {
"@types/commander": "^2.12.2",
"@types/mocha": "^5.2.6",
"@types/node": "^11.11.2",
"eslint": "^5.15.1",
"eslint-config-prettier": "^4.1.0",
"eslint-plugin-prettier": "^3.0.1",
"mocha": "^6.0.2",
"prettier": "^1.16.4"

@@ -40,0 +44,0 @@ },

@@ -19,3 +19,3 @@ # gzipper

`gzipper <path> args`
`gzipper [options] <path> [outputPath]`

@@ -37,3 +37,3 @@ Locally usage.

"scripts": {
"build": "ng build && gzipper ./dist"
"build": "ng build && gzipper --verbose ./dist"
}

@@ -46,2 +46,5 @@ ```

- `-v, --verbose` detailed level of logs
- `gl, --gzip-level` gzip compression level 0 (no compression) - 9 (best compression)
- `gm, --gzip-memory-level` amount of memory which will be allocated for compression 1 (minimum memory) - 9 (maximum memory)
- `gs, --gzip-strategy` compression strategy 1 (filtered) - 2 (huffman only) - 3 (RLE) - 4 (fixed)
- `-h, --help` output usage information

@@ -48,0 +51,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc