BlobBuilder arruina datos binarios
Tengo un problema con BlobBuilder (Chrome11) Intento obtener una imagen del servidor con una solicitud XHR. Luego trato de guardarlo en FS local con BlobBuilder / FileWriter. Cada ejemplo en Internet se trata de trabajar con texto / tipo mime simple y estos ejemplos funcionan bien. Pero cuando intento escribir datos binarios obtenidos con XHR, el tamaño del archivo se vuelve aproximadamente 1.5-2 veces mayor que el tamaño del archivo original. Y no se puede ver en Picasa / Eye Of Gnome.
var xhr = new XMLHttpRequest();
var photoOrigUrl = 'http://www.google.ru/images/nav_logo72.png';
xhr.open('GET', photoOrigUrl, true);
xhr.onreadystatechange = function() {
if (xhr.readyState == 4 && xhr.status == 200) {
var contentType = xhr.getResponseHeader('Content-type');
fsLink.root.getFile('nav_logo72.png', {'create': true}, function(fileEntry) {
fileEntry.createWriter(function(fileWriter) {
var BlobBuilderObj = new (window.BlobBuilder || window.WebKitBlobBuilder)();
BlobBuilderObj.append(xhr.responseText);
fileWriter.write(BlobBuilderObj.getBlob(contentType));
}, function(resultError) {
console.log('writing file to file system failed ( code ' + resultError.code + ')');
});
});
}
}
xhr.send();
fsLink existe, esta es una extensión.