in src/browser/FileProxy.js [236:286]
exports.write = function (successCallback, errorCallback, args) {
const fileName = args[0];
let data = args[1];
const position = args[2];
const isBinary = args[3]; // eslint-disable-line no-unused-vars
if (!data) {
if (errorCallback) {
errorCallback(FileError.INVALID_MODIFICATION_ERR);
}
return;
}
if (typeof data === 'string' || data instanceof String) {
data = new Blob([data]);
}
exports.getFile(function (fileEntry) {
let blob_ = fileEntry.file_.blob_;
if (!blob_) {
blob_ = new Blob([data], { type: data.type });
} else {
// Calc the head and tail fragments
const head = blob_.slice(0, position);
const tail = blob_.slice(position + (data.size || data.byteLength));
// Calc the padding
let padding = position - head.size;
if (padding < 0) {
padding = 0;
}
// Do the "write". In fact, a full overwrite of the Blob.
blob_ = new Blob([head, new Uint8Array(padding), data, tail],
{ type: data.type }
);
}
// Set the blob we're writing on this file entry so we can recall it later.
fileEntry.file_.blob_ = blob_;
fileEntry.file_.lastModifiedDate = new Date() || null;
fileEntry.file_.size = blob_.size;
fileEntry.file_.name = blob_.name;
fileEntry.file_.type = blob_.type;
idb_.put(fileEntry, fileEntry.file_.storagePath, function () {
successCallback(data.size || data.byteLength);
}, errorCallback);
}, errorCallback, [fileName, null]);
};