@@ -64,35 +64,21 @@ var getFileFromPathAsync = Windows.Storage.StorageFile.getFileFromPathAsync;
6464var writeBytesAsync = Windows . Storage . FileIO . writeBytesAsync ;
6565var writeTextAsync = Windows . Storage . FileIO . writeTextAsync ;
6666var 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