compressing
Advanced tools
Comparing version 1.4.0 to 1.5.0
1.5.0 / 2019-12-04 | ||
================== | ||
**features** | ||
* [[`15c29e9`](http://github.com/node-modules/compressing/commit/15c29e9893880d2c19c343d133edb50f0c55c713)] - feat: zip format support custom fileName encoding (#36) (fengmk2 <<fengmk2@gmail.com>>) | ||
**fixes** | ||
* [[`7d605fe`](http://github.com/node-modules/compressing/commit/7d605fe01a88bc6aab9a2b06a8725545f591bab9)] - fix: typescript error(#29) (Ruanyq <<yiqiang0930@163.com>>) | ||
**others** | ||
* [[`4808fb8`](http://github.com/node-modules/compressing/commit/4808fb8e1d6cbbb31c0e82c359ec04eccb0c1eaf)] - test: add node 11 (#20) (fengmk2 <<fengmk2@gmail.com>>) | ||
1.4.0 / 2018-11-30 | ||
@@ -3,0 +15,0 @@ ================== |
101
index.d.ts
@@ -1,21 +0,25 @@ | ||
import {ReadStream, WriteStream} from 'fs' | ||
import { ReadStream, WriteStream } from 'fs' | ||
type sourceType = string | Buffer | ReadStream; | ||
type sourceType = string | Buffer | ReadStream | ||
type destType = string | WriteStream; | ||
type destType = string | WriteStream | ||
type streamEntryOpts = { | ||
relativePath?: string; | ||
ignoreBase?: boolean; | ||
size?: number; | ||
interface streamEntryOpts { | ||
relativePath?: string | ||
ignoreBase?: boolean | ||
size?: number | ||
} | ||
interface streamHeader { | ||
type: 'file' | 'directory', | ||
name: 'string' | ||
} | ||
export namespace gzip { | ||
function compressFile(source: sourceType, dest: destType, opts?: any): Promise<void>; | ||
function compressFile(source: sourceType, dest: destType, opts?: any): Promise<void> | ||
function uncompress(source: sourceType, dest: destType, opts?: any): Promise<void>; | ||
function uncompress(source: sourceType, dest: destType, opts?: any): Promise<void> | ||
export class FileStream { | ||
export class FileStream extends ReadStream { | ||
@@ -29,3 +33,3 @@ constructor(opts?: { | ||
export class UncompressStream { | ||
export class UncompressStream extends WriteStream { | ||
@@ -37,3 +41,4 @@ constructor(opts?: { | ||
on(event: 'error', cb: Function) | ||
on(event: string, listener: (...args: any[]) => void): this | ||
on(event: 'error', listener: (err: Error) => void): this | ||
@@ -46,18 +51,18 @@ } | ||
function compressFile(source: sourceType, dest: destType, opts?: any): Promise<void>; | ||
function compressFile(source: sourceType, dest: destType, opts?: any): Promise<void> | ||
function compressDir(source: sourceType, dest: destType, opts?: any): Promise<void>; | ||
function compressDir(source: sourceType, dest: destType, opts?: any): Promise<void> | ||
function uncompress(source: sourceType, dest: string, opts?: any): Promise<void>; | ||
function uncompress(source: sourceType, dest: string, opts?: any): Promise<void> | ||
export class Stream { | ||
export class Stream extends ReadStream { | ||
constructor(); | ||
addEntry(entry: string, opts?: streamEntryOpts); | ||
addEntry(entry: string, opts?: streamEntryOpts): void | ||
addEntry(entry: Buffer | ReadStream, opts: streamEntryOpts); | ||
addEntry(entry: Buffer | ReadStream, opts: streamEntryOpts): void | ||
} | ||
export class FileStream { | ||
export class FileStream extends ReadStream { | ||
@@ -73,3 +78,3 @@ constructor(opts?: { | ||
export class UncompressStream { | ||
export class UncompressStream extends WriteStream { | ||
@@ -80,5 +85,7 @@ constructor(opts?: { | ||
on(event: string, listener: (...args: any[]) => void): this | ||
on(event: 'entry', listener: (header: streamHeader, stream: WriteStream, next: () => void) => void): this | ||
on(event: 'finish', listener: () => void): this | ||
on(event: 'error', listener: (err: Error) => void): this | ||
on(event: 'error', cb: Function) | ||
} | ||
@@ -90,18 +97,18 @@ | ||
function compressFile(source: sourceType, dest: destType, opts?: any): Promise<void>; | ||
function compressFile(source: sourceType, dest: destType, opts?: any): Promise<void> | ||
function compressDir(source: sourceType, dest: destType, opts?: any): Promise<void>; | ||
function compressDir(source: sourceType, dest: destType, opts?: any): Promise<void> | ||
function uncompress(source: sourceType, dest: string, opts?: any): Promise<void>; | ||
function uncompress(source: sourceType, dest: string, opts?: any): Promise<void> | ||
export class Stream { | ||
export class Stream extends ReadStream { | ||
constructor(); | ||
addEntry(entry: string, opts?: streamEntryOpts); | ||
addEntry(entry: string, opts?: streamEntryOpts): void | ||
addEntry(entry: Buffer | ReadStream, opts: streamEntryOpts); | ||
addEntry(entry: Buffer | ReadStream, opts: streamEntryOpts): void | ||
} | ||
export class FileStream { | ||
export class FileStream extends ReadStream { | ||
@@ -118,3 +125,3 @@ constructor(opts?: { | ||
export class UncompressStream { | ||
export class UncompressStream extends WriteStream { | ||
@@ -126,3 +133,6 @@ constructor(opts?: { | ||
on(event: 'entry' | 'finish' | 'error', cb: Function) | ||
on(event: string, listener: (...args: any[]) => void): this | ||
on(event: 'entry', listener: (header: streamHeader, stream: WriteStream, next: () => void) => void): this | ||
on(event: 'finish', listener: () => void): this | ||
on(event: 'error', listener: (err: Error) => void): this | ||
@@ -135,18 +145,18 @@ } | ||
function compressFile(source: sourceType, dest: destType, opts?: any): Promise<void>; | ||
function compressFile(source: sourceType, dest: destType, opts?: any): Promise<void> | ||
function compressDir(source: sourceType, dest: destType, opts?: any): Promise<void>; | ||
function compressDir(source: sourceType, dest: destType, opts?: any): Promise<void> | ||
function uncompress(source: sourceType, dest: string, opts?: any): Promise<void>; | ||
function uncompress(source: sourceType, dest: string, opts?: any): Promise<void> | ||
export class Stream { | ||
export class Stream extends ReadStream { | ||
constructor(); | ||
addEntry(entry: string, opts?: streamEntryOpts); | ||
addEntry(entry: string, opts?: streamEntryOpts): void | ||
addEntry(entry: Buffer | ReadStream, opts: streamEntryOpts); | ||
addEntry(entry: Buffer | ReadStream, opts: streamEntryOpts): void | ||
} | ||
export class FileStream { | ||
export class FileStream extends ReadStream { | ||
@@ -160,7 +170,7 @@ /** | ||
relativePath?: string, | ||
yazl?: Object, | ||
yazl?: object, | ||
source: string | ||
} | { | ||
relativePath: string, | ||
yazl?: Object, | ||
yazl?: object, | ||
source?: Buffer | ReadStream | ||
@@ -171,10 +181,14 @@ }); | ||
export class UncompressStream { | ||
export class UncompressStream extends WriteStream { | ||
constructor(opts?: { | ||
source?: sourceType, | ||
strip?: number | ||
strip?: number, | ||
zipFileNameEncoding?: string | ||
}); | ||
on(event: 'entry' | 'finish' | 'error', cb: Function) | ||
on(event: string, listener: (...args: any[]) => void): this | ||
on(event: 'entry', listener: (header: streamHeader, stream: WriteStream, next: () => void) => void): this | ||
on(event: 'finish', listener: () => void): this | ||
on(event: 'error', listener: (err: Error) => void): this | ||
@@ -184,2 +198,1 @@ } | ||
} | ||
@@ -10,2 +10,5 @@ 'use strict'; | ||
// lazy load iconv-lite | ||
let iconv; | ||
const YAUZL_CALLBACK = Symbol('ZipUncompressStream#yauzlCallback'); | ||
@@ -26,2 +29,6 @@ const STRIP_NAME = Symbol('ZipUncompressStream#stripName'); | ||
this._strip = Number(opts.strip) || 0; | ||
this._zipFileNameEncoding = opts.zipFileNameEncoding || 'utf8'; | ||
if (this._zipFileNameEncoding === 'utf-8') { | ||
this._zipFileNameEncoding = 'utf8'; | ||
} | ||
@@ -75,2 +82,13 @@ this[YAUZL_CALLBACK] = this[YAUZL_CALLBACK].bind(this); | ||
.on('entry', entry => { | ||
// fileName is buffer by default because decodeStrings = false | ||
if (Buffer.isBuffer(entry.fileName)) { | ||
if (this._zipFileNameEncoding === 'utf8') { | ||
entry.fileName = entry.fileName.toString(); | ||
} else { | ||
if (!iconv) { | ||
iconv = require('iconv-lite'); | ||
} | ||
entry.fileName = iconv.decode(entry.fileName, this._zipFileNameEncoding); | ||
} | ||
} | ||
// directory file names end with '/' | ||
@@ -77,0 +95,0 @@ const type = /\/$/.test(entry.fileName) ? 'directory' : 'file'; |
{ | ||
"name": "compressing", | ||
"version": "1.4.0", | ||
"version": "1.5.0", | ||
"description": "Everything you need for compressing and uncompressing", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "egg-bin test && tsc -p ./test/fixtures/types/tsconfig.json", | ||
"ts-test": "tsc -p ./test/fixtures/types/tsconfig.json", | ||
"test": "egg-bin test && npm run ts-test", | ||
"cov": "egg-bin cov", | ||
"lint": "eslint .", | ||
"ci": "npm run lint && npm run cov" | ||
"ci": "npm run lint && npm run ts-test && npm run cov" | ||
}, | ||
@@ -41,2 +42,3 @@ "repository": { | ||
"get-ready": "^1.0.0", | ||
"iconv-lite": "^0.5.0", | ||
"mkdirp": "^0.5.1", | ||
@@ -68,3 +70,3 @@ "pump": "^3.0.0", | ||
"ci": { | ||
"version": "4, 6, 8, 10", | ||
"version": "4, 6, 8, 10, 12", | ||
"license": { | ||
@@ -71,0 +73,0 @@ "year": "2017", |
@@ -285,3 +285,9 @@ # compressing | ||
- opts {Object} - usually you don't need it | ||
- opts.zipFileNameEncoding {String} - Only work on zip format, default is 'utf8'. | ||
Major non-UTF8 encodings by languages: | ||
- Korean: cp949, euc-kr | ||
- Japanese: sjis (shift_jis), cp932, euc-jp | ||
- Chinese: gbk, gb18030, gb2312, cp936, hkscs, big5, cp950 | ||
### FileStream | ||
@@ -373,4 +379,1 @@ | ||
https://github.com/thejoshwolfe/yauzl#no-streaming-unzip-api | ||
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
51101
935
378
9
+ Addediconv-lite@^0.5.0
+ Addediconv-lite@0.5.2(transitive)
+ Addedsafer-buffer@2.1.2(transitive)