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

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

Issue 2906283002: Take into account options.offset in onReadFileRequested. (Closed)
Patch Set: 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..9514ba7c7c377097f859ae1661f087eb4b416944 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,19 @@ function onReadFileRequested(options, onSuccess, onError) {
var contents =
METADATA[openedFiles[options.openRequestId]].contents;
+ var length = contents.length - options.offset;
+ if (length < 0) {
+ length = 0;
+ }
+ if (length > options.length) {
+ length = options.length;
+ }
mtomasz 2017/05/29 07:10:17 I think we could simplify: var remaining = Math.m
tetsui 2017/05/29 07:22:37 Done.
+
// 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