|
|
@ -140,20 +140,14 @@ angular.module('izhukov.utils', []) |
|
|
|
$window.BlobBuilder = $window.BlobBuilder || $window.WebKitBlobBuilder || $window.MozBlobBuilder; |
|
|
|
$window.BlobBuilder = $window.BlobBuilder || $window.WebKitBlobBuilder || $window.MozBlobBuilder; |
|
|
|
|
|
|
|
|
|
|
|
function fileCopyTo (fromFileEntry, toFileEntry) { |
|
|
|
function fileCopyTo (fromFileEntry, toFileEntry) { |
|
|
|
var deferred = $q.defer(); |
|
|
|
return getFileWriter(toFileEntry).then(function (fileWriter) { |
|
|
|
|
|
|
|
return fileWriteData(fileWriter, fromFileEntry).then(function () { |
|
|
|
toFileEntry.createWriter(function (fileWriter) { |
|
|
|
return fileWriter; |
|
|
|
fileWriteData(fileWriter, fromFileEntry).then(function () { |
|
|
|
}, function (error) { |
|
|
|
deferred.resolve(fileWriter); |
|
|
|
return $q.reject(error); |
|
|
|
}, function (e) { |
|
|
|
|
|
|
|
deferred.reject(e); |
|
|
|
|
|
|
|
fileWriter.truncate(0); |
|
|
|
fileWriter.truncate(0); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}, function (e) { |
|
|
|
|
|
|
|
deferred.reject(e); |
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
return deferred.promise; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function fileWriteData(fileWriter, bytes) { |
|
|
|
function fileWriteData(fileWriter, bytes) { |
|
|
@ -166,9 +160,15 @@ angular.module('izhukov.utils', []) |
|
|
|
deferred.reject(); |
|
|
|
deferred.reject(); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
if (bytes instanceof Blob) { // is file bytes
|
|
|
|
if (bytes instanceof FileEntry) { |
|
|
|
|
|
|
|
bytes.file(function (file) { |
|
|
|
|
|
|
|
fileWriter.write(file); |
|
|
|
|
|
|
|
}, fileWriter.onerror); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else if (bytes instanceof Blob) { // is file bytes
|
|
|
|
fileWriter.write(bytes); |
|
|
|
fileWriter.write(bytes); |
|
|
|
} else { |
|
|
|
} |
|
|
|
|
|
|
|
else { |
|
|
|
fileWriter.write(new Blob([bytesToArrayBuffer(bytes)])); |
|
|
|
fileWriter.write(new Blob([bytesToArrayBuffer(bytes)])); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -195,6 +195,18 @@ angular.module('izhukov.utils', []) |
|
|
|
return deferred.promise; |
|
|
|
return deferred.promise; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function getFileWriter (fileEntry) { |
|
|
|
|
|
|
|
var deferred = $q.defer(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fileEntry.createWriter(function (fileWriter) { |
|
|
|
|
|
|
|
deferred.resolve(fileWriter); |
|
|
|
|
|
|
|
}, function (error) { |
|
|
|
|
|
|
|
deferred.reject(error); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return deferred.promise; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function getFakeFileWriter (mimeType, saveFileCallback) { |
|
|
|
function getFakeFileWriter (mimeType, saveFileCallback) { |
|
|
|
var blobParts = [], |
|
|
|
var blobParts = [], |
|
|
|
fakeFileWriter = { |
|
|
|
fakeFileWriter = { |
|
|
@ -259,6 +271,7 @@ angular.module('izhukov.utils', []) |
|
|
|
return { |
|
|
|
return { |
|
|
|
copy: fileCopyTo, |
|
|
|
copy: fileCopyTo, |
|
|
|
write: fileWriteData, |
|
|
|
write: fileWriteData, |
|
|
|
|
|
|
|
getFileWriter: getFileWriter, |
|
|
|
getFakeFileWriter: getFakeFileWriter, |
|
|
|
getFakeFileWriter: getFakeFileWriter, |
|
|
|
chooseSave: chooseSaveFile, |
|
|
|
chooseSave: chooseSaveFile, |
|
|
|
getUrl: getUrl, |
|
|
|
getUrl: getUrl, |
|
|
@ -429,7 +442,7 @@ angular.module('izhukov.utils', []) |
|
|
|
fileEntry.file(function(file) { |
|
|
|
fileEntry.file(function(file) { |
|
|
|
// console.log(dT(), 'aa', file);
|
|
|
|
// console.log(dT(), 'aa', file);
|
|
|
|
if (file.size >= size) { |
|
|
|
if (file.size >= size) { |
|
|
|
deferred.resolve(fileEntry); |
|
|
|
deferred.resolve(file); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
deferred.reject(new Error('FILE_NOT_FOUND')); |
|
|
|
deferred.reject(new Error('FILE_NOT_FOUND')); |
|
|
|
} |
|
|
|
} |
|
|
@ -457,11 +470,10 @@ angular.module('izhukov.utils', []) |
|
|
|
return requestFS().then(function () { |
|
|
|
return requestFS().then(function () { |
|
|
|
var deferred = $q.defer(); |
|
|
|
var deferred = $q.defer(); |
|
|
|
cachedFs.root.getFile(fileName, {create: true}, function (fileEntry) { |
|
|
|
cachedFs.root.getFile(fileName, {create: true}, function (fileEntry) { |
|
|
|
fileEntry.createWriter(function (fileWriter) { |
|
|
|
FileManager.getFileWriter(fileEntry).then(function (fileWriter) { |
|
|
|
fileWriter.finalize = function () { |
|
|
|
fileWriter.finalize = function () { |
|
|
|
return fileEntry; |
|
|
|
return fileEntry; |
|
|
|
} |
|
|
|
} |
|
|
|
// console.log(dT(), 'got writer');
|
|
|
|
|
|
|
|
deferred.resolve(fileWriter); |
|
|
|
deferred.resolve(fileWriter); |
|
|
|
}, function (error) { |
|
|
|
}, function (error) { |
|
|
|
deferred.reject(error); |
|
|
|
deferred.reject(error); |
|
|
|