在Node.js中解压密码保护的文件

有没有一个图书馆,我可以用来解压缩密码保护的文件(网站使我下载它时在文件上的密码)? 有大量的库来解压正常的文件,但没有任何我可以find这将使用密码。

在这里,我find了一些有用的开局。 但我宁愿不诉诸使用child_process并使用内置的unix解压缩function,但这可能是我的最后一child_process 。 我甚至会对自己的encryption代码进行预处理,但我甚至无法确定如何确定encryptiontypes(这似乎只是非常标准的,因为我可以在terminal中完成)。

再次,我宁愿不这样做,但我怕这是我唯一的select,所以我已经尝试了以下几点:

 var fs = require('fs') , unzip = require('unzip') , spawn = require('child_process').spawn , expand = function(filepath, cb) { var self = this , unzipStream = fs.createReadStream(filepath).pipe(unzip.Parse()) , xmlData = ''; unzipStream.on('entry', function (entry) { var filename = entry.path; // first zip contains files and one password protected zipfile. // Here I can just do pipe(unzip.Parse()) again, but then i just get a giant encoded string that I don't know how to handle, so i tried other things bellow. if(filename.match(/\.zip$/)){ entry.on('data', function (data) { var funzip = spawn('funzip','-P','ThisIsATestPsswd','-'); var newFile = funzip.stdin.write(data); // more closing code... 

然后我有点失落了。 我试图写一个文件newFile ,但只是说[object]

然后,我尝试通过更改最后3行来简化操作

  fs.writeFile('./tmp/this.zip', data, 'binary'); var newFile = spawn('unzip','-P','ThisIsATest','./tmp/this.zip'); console.log('Data: ' + data); 

但是数据再次只是[object Object]没有用处。 我无法弄清楚下一步该怎么做,以获得这个新的解压缩文件到一个工作文件,或一个可读的string。

我是Node超级新手,所有被其他进程触发的asynchronous/侦听器都有点混乱,所以如果没有任何意义,我很抱歉。 非常感谢你的帮助!

编辑:


我现在添加了下面的代码:

 var fs = require('fs') , unzip = require('unzip') , spawn = require('child_process').spawn , expand = function(filepath, cb) { var self = this , unzipStream = fs.createReadStream(filepath) .pipe(unzip.Parse()) , xmlData = ''; unzipStream.on('entry', function (entry) { var filename = entry.path , type = entry.type // 'Directory' or 'File' , size = entry.size; console.log('Filename: ' + filename); if(filename.match(/\.zip$/)){ entry.on('data', function (data) { fs.writeFile('./lib/mocks/tmp/this.zip', data, 'binary'); var newFile = spawn('unzip','-P','ThisIsATestPassword', '-','../tmp/this.zip'); newFile.stdout.on('data', function(data){ fs.writeFile('./lib/mocks/tmp/that.txt', data); //This needs to be something different //The zip file contains an archive of files, so one file name shouldn't work }); }); } else { //Not a zip so handle differently } )}; }; 

这似乎与我所需要的非常接近,但是当写入文件时,它所具有的是用于解压缩的选项列表:

 UnZip 5.52 of 28 February 2005, by Info-ZIP. Maintained by C. Spieler. Send bug reports using http://www.info-zip.org/zip-bug.html; see README for details. Usage: unzip [-Z] [-opts[modifiers]] file[.zip] [list] [-x xlist] [-d exdir] Default action is to extract files in list, except those in xlist, to exdir; file[.zip] may be a wildcard. -Z => ZipInfo mode ("unzip -Z" for usage). -p extract files to pipe, no messages -l list files (short format) -f freshen existing files, create none -t test compressed archive data -u update files, create if necessary -z display archive comment -x exclude files that follow (in xlist) -d extract files into exdir modifiers: -q quiet mode (-qq => quieter) -n never overwrite existing files -a auto-convert any text files -o overwrite files WITHOUT prompting -aa treat ALL files as text -j junk paths (do not make directories) -v be verbose/print version info -C match filenames case-insensitively -L make (some) names lowercase -X restore UID/GID info -V retain VMS version numbers -K keep setuid/setgid/tacky permissions -M pipe through "more" pager Examples (see unzip.txt for more info): unzip data1 -x joe => extract all files except joe from zipfile data1.zip unzip -p foo | more => send contents of foo.zip via pipe into program more unzip -fo foo ReadMe => quietly replace existing ReadMe if archive file newer 

我不确定是否input错误,因为这看起来像解压缩的错误。 或者如果我只是写错了内容。 我会认为它只是通过控制台进行预处理 – 只是将所有文件提取到目录中。 虽然我希望能够从缓冲区中读取所有内容,但是 – 选项似乎没有这样做,所以我会解决刚添加到目录中的文件。 非常感谢有任何build议的人!

编辑2


我能够得到这个工作,可能不是最好的方式,但它至less使用这一行:

 var newFile = spawn('unzip', [ '-P','ThisIsATestPassword', '-d','./lib/tmp/foo','./lib/mocks/tmp/this.zip' ]) 

这将只是将所有的文件解压缩到目录中,然后我可以从那里读取它们。 我的错误是,第二个参数必须是一个数组。

我能够得到这个工作,可能不是最好的方式,但它至less使用这一行:

 var newFile = spawn('unzip', [ '-P','ThisIsATestPassword', '-d','./lib/tmp/foo','./lib/mocks/tmp/this.zip' ]) 

这将只是将所有的文件解压缩到目录中,然后我可以从那里读取它们。 我的错误是,第二个参数必须是一个数组。