我正在尝试解压缩压缩文件,如果其中一个文件是shapefile,那么将其作为变量加载。但是,从JSzip文档中,我了解到shp()函数接受缓冲区。我正在尝试转换为缓冲区,但它不工作。
console.log("Unzipping now: ");
var jsZip = new JSZip();
var fileNum =0;
jsZip.loadAsync(v_objFile).then(function (zip) {
Object.keys(zip.files).forEach(function (filename){
//now we iterate over each zipped file
zip.files[filename].async('string').then(function (fileData){
console.log("t filename: " + filename);
//if we found the shapefile file
if (filename.endsWith('.zip') == true){
zip.file(filename).async('blob').then( (blob) => {
console.log("Downloading File")
//saveAs(blob, filename);
//const buf = blob.arrayBuffer();
const buffer = new Response(blob).arrayBuffer();
shp(buffer).then(function (geojson) {
console.log(" Loaded");
// THIS CODE IS NOT REACHED
});
});
console.log("Called loadShapeFile")
}
})
})
}).catch(err => window.alert(err))
我尝试了附加的代码,但它不起作用。代码没有到达"此代码未到达">
的位置。这是我发现如何从blob转换到Arraybuffer的代码。
(async () => {
const blob = new Blob(['hello']);
const buf = await blob.arrayBuffer();
console.log( buf.byteLength ); // 5
})();