ksoichiro / node-archiver-zip-encryptable

An extension for archiver to zip with password encryption.
MIT License
12 stars 1 forks source link

require crc32-stream 3.x error. #16

Closed blackknifes closed 4 years ago

blackknifes commented 4 years ago
var CRC32Stream = require('crc32-stream');
var DeflateCRC32Stream = CRC32Stream.DeflateCRC32Stream;

Should be

var CRC32Stream = require('crc32-stream');
var DeflateCRC32Stream = CRC32Stream.DeflateCRC32Stream;
if(CRC32Stream.CRC32Stream)
  CRC32Stream = CRC32Stream.CRC32Stream;

This is my pr: #17

ksoichiro commented 4 years ago

Thank you for your report. Do you have any codes to confirm this issue or could you explain how to reproduce it? I'd like to add some test codes for this, but in my environment, executing npm test in this repository does not cause any errors.

enricosciacca commented 4 years ago

I have the same issue. With crc32-stream@3.0.1, I get

[...]/node_modules/archiver-zip-encryptable/lib/zip-crypto-stream.js:96
    : new CRC32Stream();
      ^

TypeError: CRC32Stream is not a constructor
    at module.exports.ZipCryptoStream._smartStream ([...]/node_modules/archiver-zip-encryptable/lib/zip-crypto-stream.js:96:7)
ksoichiro commented 4 years ago

Sorry but I'll close the issue because I couldn't have reproduced it, and couldn't judge that #17 is an appropriate fix. Please provide information about how to reproduce this if you still think this is a problem.

filderschoice commented 4 years ago

以前からありがたく利用させてもらっています。 本issueについて、私の環境でも再現しましたので、情報を共有させてもらいます。 サブディレクトリを持つディレクトリをarchive.directoryで暗号化圧縮した際に、エラーが再現するようです。 以前(少なくとも1ヶ月前まで)は起きていなかった事象のため、依存関係にあるパッケージ等の更新により発現した事象なのかもしれません。 また、archiverのみでzip圧縮した場合は発生しないようです。

▽再現手順 (nodeバージョン: v11.15.0) ①sample/sample2/hoge.txt を作成 ②USAGE ソースの archive.finalize() 以前に以下の1行を追記 archive.directory('sample/', 'sample1'); ③ソース実行(node index.js)

▽実行時エラー

$ node index.js
hogehoge\check-issue\node_modules\archiver-zip-en
cryptable\lib\zip-crypto-stream.js:96
    : new CRC32Stream();
      ^

TypeError: CRC32Stream is not a constructor
    at module.exports.ZipCryptoStream._smartStream (hogehoge\check-issue\node_modules\archiver-zip-encryptable\lib\zip-crypto-stream.js:96:7)

事象再現のソースも添付します。 check-issue.zip

ksoichiro commented 4 years ago

@filderschoice 情報ありがとうございます!後ほど確認させていただきます。 取り急ぎreopenしますね。

ksoichiro commented 4 years ago

I confirmed the issue. Thank you @filderschoice! And I think the causes are:

Therefore, executing npm install -S crc32-stream@2.0.0 in your project can be a workaround for this. This prevents the unintended upgrade of crc32-stream.

And in this project, #17 can be a solution for this issue, but I think we should update dependencies properly.

I'll fix this, so if you don't like the workaround, please wait for the next release.

ksoichiro commented 4 years ago

I've fixed in #18 and released as v1.0.6. I'll close this issue, but if you still think that there is a problem, please reopen it 👍