You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by sg...@apache.org on 2014/10/08 18:44:11 UTC
[1/6] git commit: Fix function write for big files on windows 8
Repository: cordova-plugin-file
Updated Branches:
refs/heads/master 1e9587ca2 -> 055e7e0bd
Fix function write for big files on windows 8
Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/commit/f9812f04
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/f9812f04
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/f9812f04
Branch: refs/heads/master
Commit: f9812f04ce42080002cc25184284d0741999d267
Parents: e35c794
Author: Florian BERTON <fl...@touchify.co>
Authored: Fri Jun 20 19:22:16 2014 +0200
Committer: SomaticIT <co...@somatic.fr>
Committed: Mon Sep 29 17:42:37 2014 +0200
----------------------------------------------------------------------
src/windows8/FileProxy.js | 69 +++++++++++++++++++++++++++++++-----------
www/FileWriter.js | 4 ++-
2 files changed, 54 insertions(+), 19 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/f9812f04/src/windows8/FileProxy.js
----------------------------------------------------------------------
diff --git a/src/windows8/FileProxy.js b/src/windows8/FileProxy.js
index 25fdee0..08ba1e5 100644
--- a/src/windows8/FileProxy.js
+++ b/src/windows8/FileProxy.js
@@ -140,7 +140,7 @@ module.exports = {
enc = args[1],
startPos = args[2],
endPos = args[3];
-
+
var encoding = Windows.Storage.Streams.UnicodeEncoding.utf8;
if (enc == 'Utf16LE' || enc == 'utf16LE') {
encoding = Windows.Storage.Streams.UnicodeEncoding.utf16LE;
@@ -423,7 +423,7 @@ module.exports = {
completePath = completePath.replace(/\\\\\\/g, '/').replace(/\\\\/g, '\\');
var fileName = completePath.substring(completePath.lastIndexOf('\\'));
-
+
//final adjustment
fullPath = completePath.substring(0, completePath.lastIndexOf('\\'));
path = fileName.replace(/\\/g, '');
@@ -518,36 +518,69 @@ module.exports = {
if (data instanceof ArrayBuffer) {
data = Array.apply(null, new Uint8Array(data));
}
-
- var writePromise = isBinary ? Windows.Storage.FileIO.writeBytesAsync : Windows.Storage.FileIO.writeTextAsync;
-
fileName = fileName.split("/").join("\\");
-
// split path to folder and file name
var path = fileName.substring(0, fileName.lastIndexOf('\\')),
file = fileName.split('\\').pop();
-
getFolderFromPathAsync(path).done(
function(storageFolder) {
storageFolder.createFileAsync(file, Windows.Storage.CreationCollisionOption.openIfExists).done(
function(storageFile) {
- writePromise(storageFile, data).
- done(function () {
- win(data.length);
- }, function () {
- fail(FileError.INVALID_MODIFICATION_ERR);
- });
- }, function() {
+ if (data instanceof Blob || data instanceof File) {
+ storageFile.openAsync(Windows.Storage.FileAccessMode.readWrite).done(
+ function (output) {
+ var input = data.msDetachStream();
+
+ // Copy the stream from the blob to the File stream
+ Windows.Storage.Streams.RandomAccessStream.copyAsync(input, output).then(
+ function () {
+ output.flushAsync().done(
+ function () {
+ input.close();
+ output.close();
+
+ win(data.length);
+ },
+ function () {
+ fail(FileError.INVALID_MODIFICATION_ERR);
+ }
+ );
+ },
+ function () {
+ fail(FileError.INVALID_MODIFICATION_ERR);
+ }
+ );
+ },
+ function () {
+ fail(FileError.INVALID_MODIFICATION_ERR);
+ }
+ );
+ }
+ else {
+ var writePromise = isBinary ? Windows.Storage.FileIO.writeBytesAsync : Windows.Storage.FileIO.writeTextAsync;
+ writePromise(storageFile, data).done(
+ function () {
+ win(data.length);
+ },
+ function () {
+ fail(FileError.INVALID_MODIFICATION_ERR);
+ }
+ );
+ }
+ },
+ function () {
fail(FileError.INVALID_MODIFICATION_ERR);
}
);
-
- }, function() {
+
+ },
+ function () {
fail(FileError.NOT_FOUND_ERR);
- });
+ }
+ );
},
truncate: function (win, fail, args) { // ["fileName","size"]
@@ -936,7 +969,7 @@ module.exports = {
}
);
}
-
+
};
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/f9812f04/www/FileWriter.js
----------------------------------------------------------------------
diff --git a/www/FileWriter.js b/www/FileWriter.js
index 786e994..68315fd 100644
--- a/www/FileWriter.js
+++ b/www/FileWriter.js
@@ -100,9 +100,11 @@ FileWriter.prototype.write = function(data) {
var that=this;
var supportsBinary = (typeof window.Blob !== 'undefined' && typeof window.ArrayBuffer !== 'undefined');
var isBinary;
+ var isWin8 = cordova.platformId === "windows8" || cordova.platformId === "windows";
// Check to see if the incoming data is a blob
- if (data instanceof File || (supportsBinary && data instanceof Blob)) {
+ if ((!isWin8 || !(data instanceof Blob || data instanceof File)) && // ignore if Windows 8
+ (data instanceof File || (supportsBinary && data instanceof Blob))) {
var fileReader = new FileReader();
fileReader.onload = function() {
// Call this method again, with the arraybuffer as argument
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org
[3/6] git commit: Make windows exception more human readable
Posted by sg...@apache.org.
Make windows exception more human readable
Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/commit/3d8a5c13
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/3d8a5c13
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/3d8a5c13
Branch: refs/heads/master
Commit: 3d8a5c13980e39f6425d40bac0a2f1ae558a4e0f
Parents: 6861386
Author: SomaticIT <co...@somatic.fr>
Authored: Tue Oct 7 18:14:13 2014 +0200
Committer: SomaticIT <co...@somatic.fr>
Committed: Tue Oct 7 18:14:13 2014 +0200
----------------------------------------------------------------------
www/FileWriter.js | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/3d8a5c13/www/FileWriter.js
----------------------------------------------------------------------
diff --git a/www/FileWriter.js b/www/FileWriter.js
index 68315fd..f009107 100644
--- a/www/FileWriter.js
+++ b/www/FileWriter.js
@@ -99,12 +99,11 @@ FileWriter.prototype.write = function(data) {
var that=this;
var supportsBinary = (typeof window.Blob !== 'undefined' && typeof window.ArrayBuffer !== 'undefined');
+ var isOkForWindows = (cordova.platformId === "windows8" || cordova.platformId === "windows") && (data instanceof Blob || data instanceof File);
var isBinary;
- var isWin8 = cordova.platformId === "windows8" || cordova.platformId === "windows";
// Check to see if the incoming data is a blob
- if ((!isWin8 || !(data instanceof Blob || data instanceof File)) && // ignore if Windows 8
- (data instanceof File || (supportsBinary && data instanceof Blob))) {
+ if (!isOkForWindows && (data instanceof File || (supportsBinary && data instanceof Blob))) {
var fileReader = new FileReader();
fileReader.onload = function() {
// Call this method again, with the arraybuffer as argument
@@ -120,7 +119,7 @@ FileWriter.prototype.write = function(data) {
// Mark data type for safer transport over the binary bridge
isBinary = supportsBinary && (data instanceof ArrayBuffer);
- if (isBinary && ['windowsphone', 'windows8'].indexOf(cordova.platformId) >= 0) {
+ if (isBinary && cordova.platformId === "windowsphone") {
// create a plain array, using the keys from the Uint8Array view so that we can serialize it
data = Array.apply(null, new Uint8Array(data));
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org
[6/6] git commit: CB-6994 Improves merged code to be able to write a
File
Posted by sg...@apache.org.
CB-6994 Improves merged code to be able to write a File
Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/commit/055e7e0b
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/055e7e0b
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/055e7e0b
Branch: refs/heads/master
Commit: 055e7e0bde7d8580ec6c992b140fa5afbb3eda7e
Parents: a631753
Author: sgrebnov <v-...@microsoft.com>
Authored: Wed Oct 8 20:42:59 2014 +0400
Committer: sgrebnov <v-...@microsoft.com>
Committed: Wed Oct 8 20:42:59 2014 +0400
----------------------------------------------------------------------
src/windows/FileProxy.js | 55 +++++++++++++++++++++++--------------------
www/FileWriter.js | 6 ++---
2 files changed, 33 insertions(+), 28 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/055e7e0b/src/windows/FileProxy.js
----------------------------------------------------------------------
diff --git a/src/windows/FileProxy.js b/src/windows/FileProxy.js
index d466e87..5d1f7ca 100644
--- a/src/windows/FileProxy.js
+++ b/src/windows/FileProxy.js
@@ -67,13 +67,7 @@ var writeBlobAsync = function writeBlobAsync(storageFile, data) {
return new WinJS.Promise(function (resolve, reject) {
storageFile.openAsync(Windows.Storage.FileAccessMode.readWrite).then(
function (output) {
- var input;
- if (data.detachStream) {
- input = data.detachStream();
- }
- else {
- input = data.msDetachStream();
- }
+ var input = (data.detachStream || data.msDetachStream).call(data);
// Copy the stream from the blob to the File stream
Windows.Storage.Streams.RandomAccessStream.copyAsync(input, output).then(
@@ -102,6 +96,10 @@ var writeBlobAsync = function writeBlobAsync(storageFile, data) {
});
};
+var writeArrayBufferAsync = function writeArrayBufferAsync(storageFile, data) {
+ return writeBlobAsync(storageFile, new Blob([data]));
+};
+
module.exports = {
getFileMetadata: function (success, fail, args) {
@@ -555,32 +553,39 @@ module.exports = {
position = args[2],
isBinary = args[3];
- if (data instanceof ArrayBuffer) {
- var dataView = new DataView(data);
- data = new Blob([dataView]);
- }
-
fileName = fileName.split("/").join("\\");
// split path to folder and file name
var path = fileName.substring(0, fileName.lastIndexOf('\\')),
file = fileName.split('\\').pop();
+ function getWriteMethodForData(data, isBinary) {
+
+ if (data instanceof Blob) {
+ return writeBlobAsync;
+ }
+
+ if (data instanceof ArrayBuffer) {
+ return writeArrayBufferAsync;
+ }
+
+ if (isBinary) {
+ return writeBytesAsync;
+ }
+
+ if (typeof data === 'string') {
+ return writeTextAsync;
+ }
+
+ throw new Error('Unsupported data type for write method');
+ }
+
+ var writePromise = getWriteMethodForData(data, isBinary);
+
getFolderFromPathAsync(path).done(
- function(storageFolder) {
+ function (storageFolder) {
storageFolder.createFileAsync(file, Windows.Storage.CreationCollisionOption.openIfExists).done(
- function(storageFile) {
- var writePromise;
- if (data instanceof Blob || data instanceof File) {
- writePromise = writeBlobAsync;
- }
- else if (isBinary) {
- writePromise = writeBytesAsync;
- }
- else {
- writePromise = writeTextAsync;
- }
-
+ function (storageFile) {
writePromise(storageFile, data).done(
function () {
win(data.length);
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/055e7e0b/www/FileWriter.js
----------------------------------------------------------------------
diff --git a/www/FileWriter.js b/www/FileWriter.js
index f009107..7f53c0c 100644
--- a/www/FileWriter.js
+++ b/www/FileWriter.js
@@ -1,4 +1,4 @@
-/*
+/*
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -99,11 +99,11 @@ FileWriter.prototype.write = function(data) {
var that=this;
var supportsBinary = (typeof window.Blob !== 'undefined' && typeof window.ArrayBuffer !== 'undefined');
- var isOkForWindows = (cordova.platformId === "windows8" || cordova.platformId === "windows") && (data instanceof Blob || data instanceof File);
+ var isProxySupportBlobNatively = (cordova.platformId === "windows8" || cordova.platformId === "windows");
var isBinary;
// Check to see if the incoming data is a blob
- if (!isOkForWindows && (data instanceof File || (supportsBinary && data instanceof Blob))) {
+ if (data instanceof File || (!isProxySupportBlobNatively && supportsBinary && data instanceof Blob)) {
var fileReader = new FileReader();
fileReader.onload = function() {
// Call this method again, with the arraybuffer as argument
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org
[4/6] git commit: Optimize FileProxy for windows platforms
Posted by sg...@apache.org.
Optimize FileProxy for windows platforms
Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/commit/3e383069
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/3e383069
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/3e383069
Branch: refs/heads/master
Commit: 3e383069afae0c230986467d80de2043895f06bf
Parents: 3d8a5c1
Author: SomaticIT <co...@somatic.fr>
Authored: Tue Oct 7 18:16:03 2014 +0200
Committer: SomaticIT <co...@somatic.fr>
Committed: Tue Oct 7 18:16:03 2014 +0200
----------------------------------------------------------------------
src/windows/FileProxy.js | 95 +++++++++++++++++++++++++-----------------
src/windows8/FileProxy.js | 95 +++++++++++++++++++++++++-----------------
2 files changed, 114 insertions(+), 76 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/3e383069/src/windows/FileProxy.js
----------------------------------------------------------------------
diff --git a/src/windows/FileProxy.js b/src/windows/FileProxy.js
index 474f044..d466e87 100644
--- a/src/windows/FileProxy.js
+++ b/src/windows/FileProxy.js
@@ -61,6 +61,46 @@ function getFilesystemFromPath(path) {
var getFolderFromPathAsync = Windows.Storage.StorageFolder.getFolderFromPathAsync;
var getFileFromPathAsync = Windows.Storage.StorageFile.getFileFromPathAsync;
+var writeBytesAsync = Windows.Storage.FileIO.writeBytesAsync;
+var writeTextAsync = Windows.Storage.FileIO.writeTextAsync;
+var writeBlobAsync = function writeBlobAsync(storageFile, data) {
+ return new WinJS.Promise(function (resolve, reject) {
+ storageFile.openAsync(Windows.Storage.FileAccessMode.readWrite).then(
+ function (output) {
+ var input;
+ if (data.detachStream) {
+ input = data.detachStream();
+ }
+ else {
+ input = data.msDetachStream();
+ }
+
+ // Copy the stream from the blob to the File stream
+ Windows.Storage.Streams.RandomAccessStream.copyAsync(input, output).then(
+ function () {
+ output.flushAsync().done(
+ function () {
+ input.close();
+ output.close();
+
+ resolve(data.length);
+ },
+ function () {
+ reject(FileError.INVALID_MODIFICATION_ERR);
+ }
+ );
+ },
+ function () {
+ reject(FileError.INVALID_MODIFICATION_ERR);
+ }
+ );
+ },
+ function () {
+ reject(FileError.INVALID_MODIFICATION_ERR);
+ }
+ );
+ });
+};
module.exports = {
@@ -516,7 +556,8 @@ module.exports = {
isBinary = args[3];
if (data instanceof ArrayBuffer) {
- data = Array.apply(null, new Uint8Array(data));
+ var dataView = new DataView(data);
+ data = new Blob([dataView]);
}
fileName = fileName.split("/").join("\\");
@@ -529,47 +570,25 @@ module.exports = {
function(storageFolder) {
storageFolder.createFileAsync(file, Windows.Storage.CreationCollisionOption.openIfExists).done(
function(storageFile) {
+ var writePromise;
if (data instanceof Blob || data instanceof File) {
- storageFile.openAsync(Windows.Storage.FileAccessMode.readWrite).done(
- function (output) {
- var input = data.msDetachStream();
-
- // Copy the stream from the blob to the File stream
- Windows.Storage.Streams.RandomAccessStream.copyAsync(input, output).then(
- function () {
- output.flushAsync().done(
- function () {
- input.close();
- output.close();
-
- win(data.length);
- },
- function () {
- fail(FileError.INVALID_MODIFICATION_ERR);
- }
- );
- },
- function () {
- fail(FileError.INVALID_MODIFICATION_ERR);
- }
- );
- },
- function () {
- fail(FileError.INVALID_MODIFICATION_ERR);
- }
- );
+ writePromise = writeBlobAsync;
+ }
+ else if (isBinary) {
+ writePromise = writeBytesAsync;
}
else {
- var writePromise = isBinary ? Windows.Storage.FileIO.writeBytesAsync : Windows.Storage.FileIO.writeTextAsync;
- writePromise(storageFile, data).done(
- function () {
- win(data.length);
- },
- function () {
- fail(FileError.INVALID_MODIFICATION_ERR);
- }
- );
+ writePromise = writeTextAsync;
}
+
+ writePromise(storageFile, data).done(
+ function () {
+ win(data.length);
+ },
+ function () {
+ fail(FileError.INVALID_MODIFICATION_ERR);
+ }
+ );
},
function () {
fail(FileError.INVALID_MODIFICATION_ERR);
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/3e383069/src/windows8/FileProxy.js
----------------------------------------------------------------------
diff --git a/src/windows8/FileProxy.js b/src/windows8/FileProxy.js
index 08ba1e5..b58eb1d 100644
--- a/src/windows8/FileProxy.js
+++ b/src/windows8/FileProxy.js
@@ -61,6 +61,46 @@ function getFilesystemFromPath(path) {
var getFolderFromPathAsync = Windows.Storage.StorageFolder.getFolderFromPathAsync;
var getFileFromPathAsync = Windows.Storage.StorageFile.getFileFromPathAsync;
+var writeBytesAsync = Windows.Storage.FileIO.writeBytesAsync;
+var writeTextAsync = Windows.Storage.FileIO.writeTextAsync;
+var writeBlobAsync = function writeBlobAsync(storageFile, data) {
+ return new WinJS.Promise(function (resolve, reject) {
+ storageFile.openAsync(Windows.Storage.FileAccessMode.readWrite).then(
+ function (output) {
+ var input;
+ if (data.detachStream) {
+ input = data.detachStream();
+ }
+ else {
+ input = data.msDetachStream();
+ }
+
+ // Copy the stream from the blob to the File stream
+ Windows.Storage.Streams.RandomAccessStream.copyAsync(input, output).then(
+ function () {
+ output.flushAsync().done(
+ function () {
+ input.close();
+ output.close();
+
+ resolve(data.length);
+ },
+ function () {
+ reject(FileError.INVALID_MODIFICATION_ERR);
+ }
+ );
+ },
+ function () {
+ reject(FileError.INVALID_MODIFICATION_ERR);
+ }
+ );
+ },
+ function () {
+ reject(FileError.INVALID_MODIFICATION_ERR);
+ }
+ );
+ });
+};
module.exports = {
@@ -516,7 +556,8 @@ module.exports = {
isBinary = args[3];
if (data instanceof ArrayBuffer) {
- data = Array.apply(null, new Uint8Array(data));
+ var dataView = new DataView(data);
+ data = new Blob([dataView]);
}
fileName = fileName.split("/").join("\\");
@@ -529,47 +570,25 @@ module.exports = {
function(storageFolder) {
storageFolder.createFileAsync(file, Windows.Storage.CreationCollisionOption.openIfExists).done(
function(storageFile) {
+ var writePromise;
if (data instanceof Blob || data instanceof File) {
- storageFile.openAsync(Windows.Storage.FileAccessMode.readWrite).done(
- function (output) {
- var input = data.msDetachStream();
-
- // Copy the stream from the blob to the File stream
- Windows.Storage.Streams.RandomAccessStream.copyAsync(input, output).then(
- function () {
- output.flushAsync().done(
- function () {
- input.close();
- output.close();
-
- win(data.length);
- },
- function () {
- fail(FileError.INVALID_MODIFICATION_ERR);
- }
- );
- },
- function () {
- fail(FileError.INVALID_MODIFICATION_ERR);
- }
- );
- },
- function () {
- fail(FileError.INVALID_MODIFICATION_ERR);
- }
- );
+ writePromise = writeBlobAsync;
+ }
+ else if (isBinary) {
+ writePromise = writeBytesAsync;
}
else {
- var writePromise = isBinary ? Windows.Storage.FileIO.writeBytesAsync : Windows.Storage.FileIO.writeTextAsync;
- writePromise(storageFile, data).done(
- function () {
- win(data.length);
- },
- function () {
- fail(FileError.INVALID_MODIFICATION_ERR);
- }
- );
+ writePromise = writeTextAsync;
}
+
+ writePromise(storageFile, data).done(
+ function () {
+ win(data.length);
+ },
+ function () {
+ fail(FileError.INVALID_MODIFICATION_ERR);
+ }
+ );
},
function () {
fail(FileError.INVALID_MODIFICATION_ERR);
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org
[5/6] git commit: Merge remote-tracking branch 'maxime/CB-6994'
Posted by sg...@apache.org.
Merge remote-tracking branch 'maxime/CB-6994'
Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/commit/a631753e
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/a631753e
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/a631753e
Branch: refs/heads/master
Commit: a631753eea52b315596b44f8028326318a821ff1
Parents: 1e9587c 3e38306
Author: sgrebnov <v-...@microsoft.com>
Authored: Wed Oct 8 19:24:11 2014 +0400
Committer: sgrebnov <v-...@microsoft.com>
Committed: Wed Oct 8 19:24:11 2014 +0400
----------------------------------------------------------------------
src/windows/FileProxy.js | 80 ++++++++++++++++++++++++++++++++-------
src/windows8/FileProxy.js | 86 +++++++++++++++++++++++++++++++++---------
www/FileWriter.js | 5 ++-
3 files changed, 138 insertions(+), 33 deletions(-)
----------------------------------------------------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org
[2/6] git commit: Synchronize changes with windows platform
Posted by sg...@apache.org.
Synchronize changes with windows platform
Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/commit/68613862
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/68613862
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/68613862
Branch: refs/heads/master
Commit: 686138622d6996bb7b3fc945115156f3b38630f7
Parents: f9812f0
Author: SomaticIT <co...@somatic.fr>
Authored: Mon Sep 29 17:46:16 2014 +0200
Committer: SomaticIT <co...@somatic.fr>
Committed: Mon Sep 29 17:48:21 2014 +0200
----------------------------------------------------------------------
src/windows/FileProxy.js | 63 ++++++++++++++++++++++++++++++++-----------
1 file changed, 48 insertions(+), 15 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/68613862/src/windows/FileProxy.js
----------------------------------------------------------------------
diff --git a/src/windows/FileProxy.js b/src/windows/FileProxy.js
index 8d36ddb..474f044 100644
--- a/src/windows/FileProxy.js
+++ b/src/windows/FileProxy.js
@@ -518,36 +518,69 @@ module.exports = {
if (data instanceof ArrayBuffer) {
data = Array.apply(null, new Uint8Array(data));
}
-
- var writePromise = isBinary ? Windows.Storage.FileIO.writeBytesAsync : Windows.Storage.FileIO.writeTextAsync;
-
fileName = fileName.split("/").join("\\");
-
// split path to folder and file name
var path = fileName.substring(0, fileName.lastIndexOf('\\')),
file = fileName.split('\\').pop();
-
getFolderFromPathAsync(path).done(
function(storageFolder) {
storageFolder.createFileAsync(file, Windows.Storage.CreationCollisionOption.openIfExists).done(
function(storageFile) {
- writePromise(storageFile, data).
- done(function () {
- win(data.length);
- }, function () {
- fail(FileError.INVALID_MODIFICATION_ERR);
- });
- }, function() {
+ if (data instanceof Blob || data instanceof File) {
+ storageFile.openAsync(Windows.Storage.FileAccessMode.readWrite).done(
+ function (output) {
+ var input = data.msDetachStream();
+
+ // Copy the stream from the blob to the File stream
+ Windows.Storage.Streams.RandomAccessStream.copyAsync(input, output).then(
+ function () {
+ output.flushAsync().done(
+ function () {
+ input.close();
+ output.close();
+
+ win(data.length);
+ },
+ function () {
+ fail(FileError.INVALID_MODIFICATION_ERR);
+ }
+ );
+ },
+ function () {
+ fail(FileError.INVALID_MODIFICATION_ERR);
+ }
+ );
+ },
+ function () {
+ fail(FileError.INVALID_MODIFICATION_ERR);
+ }
+ );
+ }
+ else {
+ var writePromise = isBinary ? Windows.Storage.FileIO.writeBytesAsync : Windows.Storage.FileIO.writeTextAsync;
+ writePromise(storageFile, data).done(
+ function () {
+ win(data.length);
+ },
+ function () {
+ fail(FileError.INVALID_MODIFICATION_ERR);
+ }
+ );
+ }
+ },
+ function () {
fail(FileError.INVALID_MODIFICATION_ERR);
}
);
-
- }, function() {
+
+ },
+ function () {
fail(FileError.NOT_FOUND_ERR);
- });
+ }
+ );
},
truncate: function (win, fail, args) { // ["fileName","size"]
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org