Chromium Code Reviews| 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. */); |