diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 261b8bb..0e621ec 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -17,8 +17,6 @@ on: pull_request: # The branches below must be a subset of the branches above branches: [ "master" ] - schedule: - - cron: '18 7 * * 5' jobs: analyze: diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index 5f3b944..4d579f4 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -12,7 +12,7 @@ on: jobs: Job: name: Node.js - uses: artusjs/github-actions/.github/workflows/node-test.yml@v1 + uses: node-modules/github-actions/.github/workflows/node-test.yml@master with: - os: 'ubuntu-latest, macos-latest' - version: '10, 12, 14, 16, 18, 19' + os: 'ubuntu-latest, macos-latest, windows-latest' + version: '14, 16, 18, 20' diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index c6cc6c8..64a499b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,17 +1,15 @@ name: Release on: - # 合并后自动发布 push: branches: [ master ] - # 手动发布 workflow_dispatch: {} jobs: release: name: Node.js - uses: artusjs/github-actions/.github/workflows/node-release.yml@v1 + uses: node-modules/github-actions/.github/workflows/node-release.yml@master secrets: NPM_TOKEN: ${{ secrets.NPM_TOKEN }} GIT_TOKEN: ${{ secrets.GIT_TOKEN }} diff --git a/CHANGELOG.md b/CHANGELOG.md index 8ee2b17..1b396cb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,3 +34,108 @@ ### Bug Fixes * throw error when source is not exists ([#78](https://github.com/node-modules/compressing/issues/78)) ([7785c72](https://github.com/node-modules/compressing/commit/7785c728d8f62b55fcce29961dc1edc54711d266)) + +--- + +1.6.2 / 2022-07-11 +================== + +**fixes** + * [[`96226d3`](http://github.com/node-modules/compressing/commit/96226d363c7c8fa9ef1a8098af646de19e729ce7)] - fix: add `suppressSizeWarning` to types and typo fix (#72) (Zeeko <>) + +1.6.1 / 2022-07-11 +================== + +**fixes** + * [[`ba49232`](http://github.com/node-modules/compressing/commit/ba49232780a57c9a3800642d7d39ae1dcdfc9409)] - fix(types): onEntry stream type should ReadStream (#73) (Songhn <>) + +**others** + * [[`054d4a4`](http://github.com/node-modules/compressing/commit/054d4a41ae4ca5d7b9b83e7298e32cc1d62d7ef4)] - 🤖 TEST: Use GitHub Action (#69) (fengmk2 <>) + +1.6.0 / 2022-06-13 +================== + +**features** + * [[`bd8ef44`](http://github.com/node-modules/compressing/commit/bd8ef44ade2f4b93d41ff2f78d6f17902d965798)] - feat: unzip should keep file mode (#68) (Artin <>) + +**others** + * [[`592e518`](http://github.com/node-modules/compressing/commit/592e5180dfbdbc6cb1becd1baf6a007ce7b7cd39)] - Create codeql-analysis.yml (fengmk2 <>) + +1.5.1 / 2020-05-11 +================== + +**fixes** + * [[`f516814`](http://github.com/node-modules/compressing/commit/f51681490aeea44a7b27ec0c09d3fb3d0385c5c0)] - fix: index.d.ts streamHeader.name wrong declearing (#46) (shadyzoz <>) + +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 <>) + +**fixes** + * [[`7d605fe`](http://github.com/node-modules/compressing/commit/7d605fe01a88bc6aab9a2b06a8725545f591bab9)] - fix: typescript error(#29) (Ruanyq <>) + +**others** + * [[`4808fb8`](http://github.com/node-modules/compressing/commit/4808fb8e1d6cbbb31c0e82c359ec04eccb0c1eaf)] - test: add node 11 (#20) (fengmk2 <>) + +1.4.0 / 2018-11-30 +================== + +**others** + * [[`1f352c8`](http://github.com/node-modules/compressing/commit/1f352c88028acf27c1881fd45d555094cb279c44)] - docs: add index.d.ts and test case (#17) (DiamondYuan <<541832074@qq.com>>) + +1.3.2 / 2018-11-21 +================== + +**fixes** + * [[`3713a0b`](http://github.com/node-modules/compressing/commit/3713a0b8d5b03d61c111afbbd4b6226169afeb14)] - fix: handle error from yazl when file not exists (#19) (DiamondYuan <<541832074@qq.com>>) + +1.3.1 / 2018-08-24 +================== + +**fixes** + * [[`b802819`](http://github.com/node-modules/compressing/commit/b8028195dd6e7200ff47c8f43f695d24838e986b)] - fix: keep stat mode when compress tar or tgz (#11) (Haoliang Gao <>) + +1.3.0 / 2018-08-13 +================== + +**features** + * [[`04feafa`](http://github.com/node-modules/compressing/commit/04feafa6a290d877044ed162ca4c7dcdc5e54e87)] - feat: support absolute path zip file (#10) (fengmk2 <>) + +1.2.4 / 2018-07-13 +================== + + * chore: replace multipipe with pump (#9) + +1.2.3 / 2017-07-27 +================== + + * fix: should resolve when all fileWriteStream finished (#7) + +1.2.2 / 2017-07-06 +================== + + * fix: make file mode correct (#6) + +1.2.1 / 2017-07-01 +================== + + * test: fix test on Windows (#4) + +1.2.0 / 2017-07-01 +================== + + * feat: add strip option when uncompress zip + +1.1.0 / 2017-02-14 +================== + + * feat: uncompress (#2) + +1.0.0 / 2016-12-24 +================== + + * rename to compressing + * feat: 1st implementation + * init diff --git a/History.md b/History.md deleted file mode 100644 index 1e6384e..0000000 --- a/History.md +++ /dev/null @@ -1,103 +0,0 @@ - -1.6.2 / 2022-07-11 -================== - -**fixes** - * [[`96226d3`](http://github.com/node-modules/compressing/commit/96226d363c7c8fa9ef1a8098af646de19e729ce7)] - fix: add `suppressSizeWarning` to types and typo fix (#72) (Zeeko <>) - -1.6.1 / 2022-07-11 -================== - -**fixes** - * [[`ba49232`](http://github.com/node-modules/compressing/commit/ba49232780a57c9a3800642d7d39ae1dcdfc9409)] - fix(types): onEntry stream type should ReadStream (#73) (Songhn <>) - -**others** - * [[`054d4a4`](http://github.com/node-modules/compressing/commit/054d4a41ae4ca5d7b9b83e7298e32cc1d62d7ef4)] - 🤖 TEST: Use GitHub Action (#69) (fengmk2 <>) - -1.6.0 / 2022-06-13 -================== - -**features** - * [[`bd8ef44`](http://github.com/node-modules/compressing/commit/bd8ef44ade2f4b93d41ff2f78d6f17902d965798)] - feat: unzip should keep file mode (#68) (Artin <>) - -**others** - * [[`592e518`](http://github.com/node-modules/compressing/commit/592e5180dfbdbc6cb1becd1baf6a007ce7b7cd39)] - Create codeql-analysis.yml (fengmk2 <>) - -1.5.1 / 2020-05-11 -================== - -**fixes** - * [[`f516814`](http://github.com/node-modules/compressing/commit/f51681490aeea44a7b27ec0c09d3fb3d0385c5c0)] - fix: index.d.ts streamHeader.name wrong declearing (#46) (shadyzoz <>) - -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 <>) - -**fixes** - * [[`7d605fe`](http://github.com/node-modules/compressing/commit/7d605fe01a88bc6aab9a2b06a8725545f591bab9)] - fix: typescript error(#29) (Ruanyq <>) - -**others** - * [[`4808fb8`](http://github.com/node-modules/compressing/commit/4808fb8e1d6cbbb31c0e82c359ec04eccb0c1eaf)] - test: add node 11 (#20) (fengmk2 <>) - -1.4.0 / 2018-11-30 -================== - -**others** - * [[`1f352c8`](http://github.com/node-modules/compressing/commit/1f352c88028acf27c1881fd45d555094cb279c44)] - docs: add index.d.ts and test case (#17) (DiamondYuan <<541832074@qq.com>>) - -1.3.2 / 2018-11-21 -================== - -**fixes** - * [[`3713a0b`](http://github.com/node-modules/compressing/commit/3713a0b8d5b03d61c111afbbd4b6226169afeb14)] - fix: handle error from yazl when file not exists (#19) (DiamondYuan <<541832074@qq.com>>) - -1.3.1 / 2018-08-24 -================== - -**fixes** - * [[`b802819`](http://github.com/node-modules/compressing/commit/b8028195dd6e7200ff47c8f43f695d24838e986b)] - fix: keep stat mode when compress tar or tgz (#11) (Haoliang Gao <>) - -1.3.0 / 2018-08-13 -================== - -**features** - * [[`04feafa`](http://github.com/node-modules/compressing/commit/04feafa6a290d877044ed162ca4c7dcdc5e54e87)] - feat: support absolute path zip file (#10) (fengmk2 <>) - -1.2.4 / 2018-07-13 -================== - - * chore: replace multipipe with pump (#9) - -1.2.3 / 2017-07-27 -================== - - * fix: should resolve when all fileWriteStream finished (#7) - -1.2.2 / 2017-07-06 -================== - - * fix: make file mode correct (#6) - -1.2.1 / 2017-07-01 -================== - - * test: fix test on Windows (#4) - -1.2.0 / 2017-07-01 -================== - - * feat: add strip option when uncompress zip - -1.1.0 / 2017-02-14 -================== - - * feat: uncompress (#2) - -1.0.0 / 2016-12-24 -================== - - * rename to compressing - * feat: 1st implementation - * init diff --git a/README.md b/README.md index b1e6b5f..0f4abc9 100644 --- a/README.md +++ b/README.md @@ -368,10 +368,11 @@ Although the API is streaming style(try to keep it handy), it still loads all da ## Contributors -|[
shaoshuai0102](https://github.com/shaoshuai0102)
|[
fengmk2](https://github.com/fengmk2)
|[
popomore](https://github.com/popomore)
|[
DiamondYuan](https://github.com/DiamondYuan)
|[
bytemain](https://github.com/bytemain)
|[
Ryqsky](https://github.com/Ryqsky)
| +|[
fengmk2](https://github.com/fengmk2)
|[
shaoshuai0102](https://github.com/shaoshuai0102)
|[
popomore](https://github.com/popomore)
|[
semantic-release-bot](https://github.com/semantic-release-bot)
|[
DiamondYuan](https://github.com/DiamondYuan)
|[
acyza](https://github.com/acyza)
| | :---: | :---: | :---: | :---: | :---: | :---: | -[
songhn233](https://github.com/songhn233)
|[
ShadyZOZ](https://github.com/ShadyZOZ)
+|[
bytemain](https://github.com/bytemain)
|[
rickyes](https://github.com/rickyes)
|[
Ryqsky](https://github.com/Ryqsky)
|[
songhn233](https://github.com/songhn233)
|[
Infiltrator](https://github.com/Infiltrator)
|[
ZeekoZhu](https://github.com/ZeekoZhu)
| +[
killagu](https://github.com/killagu)
|[
okaponta](https://github.com/okaponta)
|[
ShadyZOZ](https://github.com/ShadyZOZ)
-This project follows the git-contributor [spec](https://github.com/xudafeng/git-contributor), auto updated at `Mon Jul 11 2022 08:28:25 GMT+0800`. +This project follows the git-contributor [spec](https://github.com/xudafeng/git-contributor), auto updated at `Thu Aug 03 2023 01:39:37 GMT+0800`. diff --git a/lib/utils.js b/lib/utils.js index 5af3bc2..94a2b8d 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -139,12 +139,12 @@ exports.streamToBuffer = stream => { return new Promise((resolve, reject) => { const chunks = []; stream - .on('readable', () => { - let chunk; - while ((chunk = stream.read())) chunks.push(chunk); - }) - .on('end', () => resolve(Buffer.concat(chunks))) - .on('error', err => reject(err)); + .on('readable', () => { + let chunk; + while ((chunk = stream.read())) chunks.push(chunk); + }) + .on('end', () => resolve(Buffer.concat(chunks))) + .on('error', err => reject(err)); }); }; diff --git a/lib/zip/uncompress_stream.js b/lib/zip/uncompress_stream.js index 8c569ae..bbdd218 100644 --- a/lib/zip/uncompress_stream.js +++ b/lib/zip/uncompress_stream.js @@ -56,8 +56,8 @@ class ZipUncompressStream extends UncompressBaseStream { if (sourceType === 'stream') { utils.streamToBuffer(opts.source) - .then(buf => yauzl.fromBuffer(buf, yauzlOpts, this[YAUZL_CALLBACK])) - .catch(e => this.emit('error', e)); + .then(buf => yauzl.fromBuffer(buf, yauzlOpts, this[YAUZL_CALLBACK])) + .catch(e => this.emit('error', e)); return; } @@ -65,12 +65,12 @@ class ZipUncompressStream extends UncompressBaseStream { srcStream.unpipe(srcStream); utils.streamToBuffer(srcStream) - .then(buf => { - this._chunks.push(buf); - buf = Buffer.concat(this._chunks); - yauzl.fromBuffer(buf, yauzlOpts, this[YAUZL_CALLBACK]); - }) - .catch(e => this.emit('error', e)); + .then(buf => { + this._chunks.push(buf); + buf = Buffer.concat(this._chunks); + yauzl.fromBuffer(buf, yauzlOpts, this[YAUZL_CALLBACK]); + }) + .catch(e => this.emit('error', e)); }); } @@ -85,38 +85,38 @@ class ZipUncompressStream extends UncompressBaseStream { zipFile.readEntry(); zipFile - .on('entry', entry => { - const mode = modeFromEntry(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'); + .on('entry', entry => { + const mode = modeFromEntry(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); } - entry.fileName = iconv.decode(entry.fileName, this._zipFileNameEncoding); } - } - // directory file names end with '/' - const type = /\/$/.test(entry.fileName) ? 'directory' : 'file'; - const name = entry.fileName = this[STRIP_NAME](entry.fileName, type); - - const header = { name, type, yauzl: entry, mode }; - - if (type === 'file') { - zipFile.openReadStream(entry, (err, readStream) => { - if (err) return this.emit('error', err); - this.emit('entry', header, readStream, next); - }); - } else { // directory - const placeholder = new stream.Readable({ read() {} }); - this.emit('entry', header, placeholder, next); - setImmediate(() => placeholder.emit('end')); - } - }) - .on('end', () => this.emit('finish')) - .on('error', err => this.emit('error', err)); + // directory file names end with '/' + const type = /\/$/.test(entry.fileName) ? 'directory' : 'file'; + const name = entry.fileName = this[STRIP_NAME](entry.fileName, type); + + const header = { name, type, yauzl: entry, mode }; + + if (type === 'file') { + zipFile.openReadStream(entry, (err, readStream) => { + if (err) return this.emit('error', err); + this.emit('entry', header, readStream, next); + }); + } else { // directory + const placeholder = new stream.Readable({ read() {} }); + this.emit('entry', header, placeholder, next); + setImmediate(() => placeholder.emit('end')); + } + }) + .on('end', () => this.emit('finish')) + .on('error', err => this.emit('error', err)); function next() { zipFile.readEntry(); diff --git a/package.json b/package.json index db4f203..533fef1 100644 --- a/package.json +++ b/package.json @@ -6,8 +6,8 @@ "scripts": { "contributor": "git-contributor", "ts-test": "tsc -p ./test/fixtures/types/tsconfig.json", - "test": "egg-bin test --espower=false --full-trace && npm run ts-test", - "cov": "egg-bin cov --espower=false", + "test": "egg-bin test --ts false && npm run ts-test", + "cov": "egg-bin cov --ts false", "lint-fix": "eslint . --fix", "lint": "eslint .", "ci": "npm run lint && npm run ts-test && npm run cov" @@ -50,17 +50,16 @@ "yazl": "^2.4.2" }, "devDependencies": { - "@types/mocha": "^5.2.5", - "@types/node": "^10.12.9", + "@types/mocha": "10", + "@types/node": "20", "dir-compare": "^1.3.0", - "egg-bin": "4", - "eslint": "^3.10.2", - "eslint-config-egg": "^3.2.0", - "git-contributor": "^1.1.0", + "egg-bin": "6", + "eslint": "8", + "eslint-config-egg": "12", + "git-contributor": "2", "mm": "^2.0.0", "mz-modules": "^2.1.0", - "rimraf": "^2.6.2", - "typescript": "^3.1.6", + "typescript": "5", "uuid": "^3.0.1" }, "engines": { diff --git a/test/gzip/uncompress_stream.test.js b/test/gzip/uncompress_stream.test.js index 85ec9e4..653de02 100644 --- a/test/gzip/uncompress_stream.test.js +++ b/test/gzip/uncompress_stream.test.js @@ -1,5 +1,3 @@ -'use strict'; - const fs = require('fs'); const mm = require('mm'); const os = require('os'); @@ -7,14 +5,14 @@ const uuid = require('uuid'); const path = require('path'); const assert = require('assert'); const pump = require('pump'); -const compressing = require('../..'); const streamifier = require('streamifier'); +const compressing = require('../..'); const originalFile = path.join(__dirname, '..', 'fixtures', 'xx.log'); const sourceFile = path.join(__dirname, '..', 'fixtures', 'xx.log.gz'); +const isWindows = os.platform() === 'win32'; describe('test/gzip/uncompress_stream.test.js', () => { - afterEach(mm.restore); it('should be transform stream', done => { @@ -26,7 +24,13 @@ describe('test/gzip/uncompress_stream.test.js', () => { pump(sourceStream, uncompressStream, destStream, err => { assert(!err); assert(fs.existsSync(destFile)); - assert(fs.readFileSync(destFile, 'utf8') === fs.readFileSync(originalFile, 'utf8')); + const originalFileBuffer = fs.readFileSync(originalFile); + const destFileBuffer = fs.readFileSync(destFile); + assert.equal(destFileBuffer.size, originalFileBuffer.size); + if (!isWindows) { + // EOL not equal to linux + assert.equal(destFileBuffer.toString('utf8'), originalFileBuffer.toString('utf8')); + } done(); }); }); @@ -39,7 +43,12 @@ describe('test/gzip/uncompress_stream.test.js', () => { pump(uncompressStream, destStream, err => { assert(!err); assert(fs.existsSync(destFile)); - assert(fs.readFileSync(destFile, 'utf8') === fs.readFileSync(originalFile, 'utf8')); + const originalFileBuffer = fs.readFileSync(originalFile); + const destFileBuffer = fs.readFileSync(destFile); + assert.equal(destFileBuffer.size, originalFileBuffer.size); + if (!isWindows) { + assert.equal(destFileBuffer.toString('utf8'), originalFileBuffer.toString('utf8')); + } done(); }); }); @@ -53,7 +62,12 @@ describe('test/gzip/uncompress_stream.test.js', () => { pump(uncompressStream, destStream, err => { assert(!err); assert(fs.existsSync(destFile)); - assert(fs.readFileSync(destFile, 'utf8') === fs.readFileSync(originalFile, 'utf8')); + const originalFileBuffer = fs.readFileSync(originalFile); + const destFileBuffer = fs.readFileSync(destFile); + assert.equal(destFileBuffer.size, originalFileBuffer.size); + if (!isWindows) { + assert.equal(destFileBuffer.toString('utf8'), originalFileBuffer.toString('utf8')); + } done(); }); }); @@ -67,7 +81,12 @@ describe('test/gzip/uncompress_stream.test.js', () => { pump(uncompressStream, destStream, err => { assert(!err); assert(fs.existsSync(destFile)); - assert(fs.readFileSync(destFile, 'utf8') === fs.readFileSync(originalFile, 'utf8')); + const originalFileBuffer = fs.readFileSync(originalFile); + const destFileBuffer = fs.readFileSync(destFile); + assert.equal(destFileBuffer.size, originalFileBuffer.size); + if (!isWindows) { + assert.equal(destFileBuffer.toString('utf8'), originalFileBuffer.toString('utf8')); + } done(); }); }); diff --git a/test/zip/index.test.js b/test/zip/index.test.js index dc6a124..750c192 100644 --- a/test/zip/index.test.js +++ b/test/zip/index.test.js @@ -1,10 +1,7 @@ -'use strict'; - const fs = require('fs'); const os = require('os'); const path = require('path'); const uuid = require('uuid'); -const rimraf = require('rimraf'); const mkdirp = require('mkdirp'); const compressing = require('../..'); const assert = require('assert'); @@ -13,7 +10,9 @@ const dircompare = require('dir-compare'); describe('test/zip/index.test.js', () => { let destDir; afterEach(() => { - rimraf.sync(destDir); + if (destDir) { + fs.rmSync(destDir, { force: true, recursive: true }); + } }); describe('zip.compressFile()', () => { @@ -239,7 +238,7 @@ describe('test/zip/index.test.js', () => { 'index.html', 'styles', ]); - rimraf.sync(destDir); + fs.rmSync(destDir, { force: true, recursive: true }); }); it('zip.uncompress(sourceStream, destDir)', function* () {