Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5166)

Unified Diff: chrome/common/extensions/docs/examples/api/fileSystemProvider/basic/background.js

Issue 2906283002: Take into account options.offset in onReadFileRequested. (Closed)
Patch Set: Fix nits. Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/common/extensions/docs/examples/api/fileSystemProvider/basic/background.js
diff --git a/chrome/common/extensions/docs/examples/api/fileSystemProvider/basic/background.js b/chrome/common/extensions/docs/examples/api/fileSystemProvider/basic/background.js
index bf78eb4ef8804de0b4d64d1f2e4dc6fd2f306fe5..8c08f428e0df6636a3b40c802757ae65e3122dd4 100644
--- a/chrome/common/extensions/docs/examples/api/fileSystemProvider/basic/background.js
+++ b/chrome/common/extensions/docs/examples/api/fileSystemProvider/basic/background.js
@@ -89,11 +89,14 @@ function onReadFileRequested(options, onSuccess, onError) {
var contents =
METADATA[openedFiles[options.openRequestId]].contents;
+ var remaining = Math.max(0, contents.length - options.offset);
+ var length = Math.min(remaining, options.length);
+
// Write the contents as ASCII text.
- var buffer = new ArrayBuffer(options.length);
+ var buffer = new ArrayBuffer(length);
var bufferView = new Uint8Array(buffer);
- for (var i = 0; i < options.length; i++) {
- bufferView[i] = contents.charCodeAt(i);
+ for (var i = 0; i < length; i++) {
+ bufferView[i] = contents.charCodeAt(i + options.offset);
}
onSuccess(buffer, false /* Last call. */);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698