Add win8 support for readAsBinaryString and readAsArrayBuffer 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/5ddef30e Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/5ddef30e Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/5ddef30e
Branch: refs/heads/master Commit: 5ddef30ef6f60e2fb1aa13f82984448dba838093 Parents: 2396549 Author: Eion Robb <[email protected]> Authored: Fri Jun 13 09:09:30 2014 +1200 Committer: Eion Robb <[email protected]> Committed: Fri Jun 13 09:09:30 2014 +1200 ---------------------------------------------------------------------- src/windows8/FileProxy.js | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/5ddef30e/src/windows8/FileProxy.js ---------------------------------------------------------------------- diff --git a/src/windows8/FileProxy.js b/src/windows8/FileProxy.js index 93be55b..8e1b85d 100644 --- a/src/windows8/FileProxy.js +++ b/src/windows8/FileProxy.js @@ -187,6 +187,47 @@ module.exports = { ); }, + readAsBinaryString:function(win,fail,args) { + var fileName = args[0]; + + + Windows.Storage.StorageFile.getFileFromPathAsync(fileName).then( + function (storageFile) { + Windows.Storage.FileIO.readBufferAsync(storageFile).done( + function (buffer) { + var dataReader = Windows.Storage.Streams.DataReader.fromBuffer(buffer); + var fileContent = dataReader.readString(buffer.length); + dataReader.close(); + win(fileContent); + } + ); + }, function () { + fail && fail(FileError.NOT_FOUND_ERR); + } + ); + }, + + readAsArrayBuffer:function(win,fail,args) { + var fileName = args[0]; + + + Windows.Storage.StorageFile.getFileFromPathAsync(fileName).then( + function (storageFile) { + var blob = MSApp.createFileFromStorageFile(storageFile); + var url = URL.createObjectURL(blob, { oneTimeOnly: true }); + var xhr = new XMLHttpRequest(); + xhr.open("GET", url, true); + xhr.responseType = 'arraybuffer'; + xhr.onload = function() { + win(xhr.response); + }; + xhr.send(); + }, function () { + fail && fail(FileError.NOT_FOUND_ERR); + } + ); + }, + getDirectory:function(win,fail,args) { var fullPath = args[0]; var path = args[1];
