sto provando a:utilizzando zip.js di leggere un file zip tramite XMLHTTP/chiamata AJAX su Node.js
- Invia un file zip tramite XMLHTTP al cliente
- quindi leggere il file usando zip.js e rendere il suo contenuto
ricevo con successo il binario del file cioè il callback successo si chiama ma ottengo ed errore quando provo a fare GetEntries. Penso che l'errore è con il modo di inviare stream, per favore aiutatemi.
errore msg:
Errore nella lettura del file zip
Il mio codice lato client (utilizzando angolare):
$http.get(window.location.origin + '/book/'+bookName,{responseType:"Blob"}).
success(function (data , error) {
var a = new Uint8Array(data);
//var dataView = new DataView(data);
//var blob = new Blob(dataView.buffer);
zip.useWebWorkers = true;
zip.workerScriptsPath = '/js/app/';
zip.createReader(new zip.BlobReader(data), function(reader) {
// get all entries from the zip
reader.getEntries(function(entries) { //HERE I GET THE ERROR
if (entries.length) {
// get first entry content as text
entries[0].getData(new zip.TextWriter(), function(text) {
// text contains the entry data as a String
console.log(text);
// close the zip reader
reader.close(function() {
// onclose callback
var a = 0;
});
}, function(current, total) {
// onprogress callback
var a = 0;
});
}
});
},
function(error) {
// onerror callback
var a = 0;
});
})
.error(function (data , error) {
var a = 0;
});
mio codice lato server sul nodo:
router.get('/book/:bookName',function (req , res) {
console.log('Inside book reading block : ' + req.params.bookName);
req.params.bookName += '.zip';
var filePath = path.join(__dirname,'/../\\public\\books\\' ,req.params.bookName);
var stat = fileSystem.statSync(filePath);
res.writeHead(200, {
//'Content-Type': 'application/zip',
'Content-Type': 'blob',
'Content-Length': stat.size
});
var readStream = fileSystem.createReadStream(filePath);
// replace all the event handlers with a simple call to readStream.pipe()
readStream.pipe(res);
});
A valle senza un commento. Potresti almeno condividere la ragione. – Sandeep