gpt4 book ai didi

node.js - nodejs从url下载并解压文件,错误No END header found

转载 作者:搜寻专家 更新时间:2023-10-31 22:19:52 25 4
gpt4 key购买 nike

我正在尝试从 nseindia.com 下载文件并在内存中解压缩。我正在使用 nodejs webkit 和 adm-zip。我在控制台上收到错误消息:

Uncaught Invalid or unsupported zip format. No END header found

代码:

var http = require('http'),
fs = require('fs'),
request = require('request'),
AdmZip = require('adm-zip'),
out = fs.createWriteStream('data/nseeqbhav.zip'); // For saving NSE Equity bhavcopy


// Downloading NSE Bhavcopy
request(
{ method: 'GET',
uri: 'http://www.nseindia.com/content/historical/EQUITIES/2012/DEC/cm19DEC2012bhav.csv.zip',
headers: { "User-Agent": "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.97 Safari/537.11",
"Referer": "http://www.nseindia.com/products/content/all_daily_reports.htm",
"Accept-Encoding": "gzip,deflate,sdch",
"encoding": "null",
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
"Cookie": "cookie"
}
}
).pipe(out);
var zip = new AdmZip("data/nseeqbhav.zip"),
zipEntries = zip.getEntries();
zip.extractAllTo(/*target path*/"data/unzip/", /*overwrite*/true);

我尝试跟随以结束直播,但没有成功。

out.end();
out.destroy();

提前致谢。

最佳答案

您正在尝试在文件完全写入之前读取文件。您需要等待写入完成。

var http = require('http'),
fs = require('fs'),
request = require('request'),
AdmZip = require('adm-zip'),
out = fs.createWriteStream('data/nseeqbhav.zip'); // For saving NSE Equity bhavcopy

// Downloading NSE Bhavcopy
var req = request(
{
method: 'GET',
uri: 'http://www.nseindia.com/content/historical/EQUITIES/2012/DEC/cm19DEC2012bhav.csv.zip',
headers: { "User-Agent": "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.97 Safari/537.11",
"Referer": "http://www.nseindia.com/products/content/all_daily_reports.htm",
"Accept-Encoding": "gzip,deflate,sdch",
"encoding": "null",
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
"Cookie": "cookie"
}
}
);

req.pipe(out);
req.on('end', function() {
var zip = new AdmZip("data/nseeqbhav.zip"),
zipEntries = zip.getEntries();
zip.extractAllTo(/*target path*/"data/unzip/", /*overwrite*/true);
});

关于node.js - nodejs从url下载并解压文件,错误No END header found,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14107470/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com