Skip to content

Commit cfcb74c

Browse files
author
Vladimir Kotikov
committed
CB-6994 Fixes result, returned by proxy's write method
+ Refactors writeBlobAsync function + Fixes proxy's remove method failure when trying to delete non-existent file
1 parent 8133568 commit cfcb74c

File tree

1 file changed

+19
-35
lines changed

1 file changed

+19
-35
lines changed

src/windows/FileProxy.js

Lines changed: 19 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -64,35 +64,21 @@ var getFileFromPathAsync = Windows.Storage.StorageFile.getFileFromPathAsync;
6464
var writeBytesAsync = Windows.Storage.FileIO.writeBytesAsync;
6565
var writeTextAsync = Windows.Storage.FileIO.writeTextAsync;
6666
var writeBlobAsync = function writeBlobAsync(storageFile, data) {
67-
return new WinJS.Promise(function (resolve, reject) {
68-
storageFile.openAsync(Windows.Storage.FileAccessMode.readWrite).then(
69-
function (output) {
70-
var input = (data.detachStream || data.msDetachStream).call(data);
71-
72-
// Copy the stream from the blob to the File stream
73-
Windows.Storage.Streams.RandomAccessStream.copyAsync(input, output).then(
74-
function () {
75-
output.flushAsync().done(
76-
function () {
77-
input.close();
78-
output.close();
79-
80-
resolve(data.length);
81-
},
82-
function () {
83-
reject(FileError.INVALID_MODIFICATION_ERR);
84-
}
85-
);
86-
},
87-
function () {
88-
reject(FileError.INVALID_MODIFICATION_ERR);
89-
}
90-
);
91-
},
92-
function () {
93-
reject(FileError.INVALID_MODIFICATION_ERR);
94-
}
95-
);
67+
return storageFile.openAsync(Windows.Storage.FileAccessMode.readWrite)
68+
.then(function (output) {
69+
var dataSize = data.size;
70+
var input = (data.detachStream || data.msDetachStream).call(data);
71+
72+
// Copy the stream from the blob to the File stream
73+
return Windows.Storage.Streams.RandomAccessStream.copyAsync(input, output)
74+
.then(function () {
75+
return output.flushAsync().then(function () {
76+
input.close();
77+
output.close();
78+
79+
return dataSize;
80+
});
81+
});
9682
});
9783
};
9884

@@ -363,12 +349,9 @@ module.exports = {
363349
var fullPath = cordovaPathToNative(args[0]);
364350

365351
getFileFromPathAsync(fullPath).then(
366-
function (sFile) {
367-
getFileFromPathAsync(fullPath).done(function (storageFile) {
352+
function (storageFile) {
368353
storageFile.deleteAsync().done(win, function () {
369354
fail(FileError.INVALID_MODIFICATION_ERR);
370-
371-
});
372355
});
373356
},
374357
function () {
@@ -587,8 +570,9 @@ module.exports = {
587570
storageFolder.createFileAsync(file, Windows.Storage.CreationCollisionOption.openIfExists).done(
588571
function (storageFile) {
589572
writePromise(storageFile, data).done(
590-
function () {
591-
win(data.length);
573+
function (bytesWritten) {
574+
var written = bytesWritten || data.length;
575+
win(written);
592576
},
593577
function () {
594578
fail(FileError.INVALID_MODIFICATION_ERR);

0 commit comments

Comments
 (0)