You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by br...@apache.org on 2013/01/08 00:10:47 UTC
[1/4] js commit: First pass at implementing File.slice()
First pass at implementing File.slice()
Project: http://git-wip-us.apache.org/repos/asf/cordova-js/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-js/commit/85cd7b12
Tree: http://git-wip-us.apache.org/repos/asf/cordova-js/tree/85cd7b12
Diff: http://git-wip-us.apache.org/repos/asf/cordova-js/diff/85cd7b12
Branch: refs/heads/master
Commit: 85cd7b12ed3af28273adbce476f438279870166e
Parents: d8204cc
Author: Braden Shepherdson <br...@chromium.org>
Authored: Tue Dec 18 18:36:26 2012 -0500
Committer: Braden Shepherdson <br...@chromium.org>
Committed: Tue Dec 18 18:36:26 2012 -0500
----------------------------------------------------------------------
lib/common/plugin/File.js | 27 +++++++++++++++++++++++++++
lib/common/plugin/FileReader.js | 22 ++++++++++++++++++++--
2 files changed, 47 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-js/blob/85cd7b12/lib/common/plugin/File.js
----------------------------------------------------------------------
diff --git a/lib/common/plugin/File.js b/lib/common/plugin/File.js
index 7a3ff3e..8e59cf1 100644
--- a/lib/common/plugin/File.js
+++ b/lib/common/plugin/File.js
@@ -34,6 +34,33 @@ var File = function(name, fullPath, type, lastModifiedDate, size){
this.type = type || null;
this.lastModifiedDate = lastModifiedDate || null;
this.size = size || 0;
+ this.start = 0;
+ this.end = size;
};
+File.prototype.slice = function(start, end) {
+ if (arguments.length == 0) {
+ this.start = 0;
+ this.end = this.size;
+ return;
+ }
+
+ if (arguments.length >= 1) {
+ if (start < 0) {
+ this.start = Math.max(this.size + start, 0);
+ } else {
+ this.start = Math.min(this.size, start);
+ }
+ }
+
+ if (arguments.length >= 2) {
+ if (end < 0) {
+ this.end = Math.max(this.size + end, 0);
+ } else {
+ this.end = Math.min(end, this.size);
+ }
+ }
+};
+
+
module.exports = File;
http://git-wip-us.apache.org/repos/asf/cordova-js/blob/85cd7b12/lib/common/plugin/FileReader.js
----------------------------------------------------------------------
diff --git a/lib/common/plugin/FileReader.js b/lib/common/plugin/FileReader.js
index e27ba04..2169b79 100644
--- a/lib/common/plugin/FileReader.js
+++ b/lib/common/plugin/FileReader.js
@@ -111,6 +111,15 @@ FileReader.prototype.readAsText = function(file, encoding) {
var me = this;
+ var execArgs = [this.fileName, enc];
+
+ // Maybe add slice parameters.
+ if (file.end < file.size) {
+ execArgs.push(file.start, file.end);
+ } else if (file.start > 0) {
+ execArgs.push(file.start);
+ }
+
// Read file
exec(
// Success callback
@@ -161,7 +170,7 @@ FileReader.prototype.readAsText = function(file, encoding) {
if (typeof me.onloadend === "function") {
me.onloadend(new ProgressEvent("loadend", {target:me}));
}
- }, "File", "readAsText", [this.fileName, enc]);
+ }, "File", "readAsText", execArgs);
};
@@ -195,6 +204,15 @@ FileReader.prototype.readAsDataURL = function(file) {
var me = this;
+ var execArgs = [this.fileName];
+
+ // Maybe add slice parameters.
+ if (file.end < file.size) {
+ execArgs.push(file.start, file.end);
+ } else if (file.start > 0) {
+ execArgs.push(file.start);
+ }
+
// Read file
exec(
// Success callback
@@ -244,7 +262,7 @@ FileReader.prototype.readAsDataURL = function(file) {
if (typeof me.onloadend === "function") {
me.onloadend(new ProgressEvent("loadend", {target:me}));
}
- }, "File", "readAsDataURL", [this.fileName]);
+ }, "File", "readAsDataURL", execArgs);
};
/**