我正在将base64
编码的值写入zip文件。以下是我使用的写入代码:
var base64Data = base64_encoded_value;
base64Data += base64Data.replace('+', ' ');
binaryData = new Buffer(base64Data, 'base64').toString('binary');
fs.writeFile('test.zip', binaryData, "binary", function (err) {
console.log(err); // writes out file without error
});
代码已经运行成功,创建了test.zip
文件,但问题是当我试图解压它时,出现了以下错误:
End-of-central-directory signature not found. Either this file is not
a zipfile, or it constitutes one disk of a multi-part archive. In the
latter case the central directory and zipfile comment will be found on
the last disk(s) of this archive.
unzip: cannot find zipfile directory in one of /home/user/Node/project/public/media/written/zip4045508057.zip or
/home/user/Node/project/public/media/written/zip4045508057.zip.zip, and cannot find /home/user/Node/project/public/media/written/zip4045508057.zip.ZIP, period.
有没有办法做到这一点?