Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 'use strict'; | 5 'use strict'; |
| 6 | 6 |
| 7 // Fake data similar to a file system structure. | 7 // Fake data similar to a file system structure. |
| 8 var MODIFICATION_DATE = new Date(); | 8 var MODIFICATION_DATE = new Date(); |
| 9 var SHORT_CONTENTS = 'Just another example.'; | 9 var SHORT_CONTENTS = 'Just another example.'; |
| 10 var LONGER_CONTENTS = 'It works!\nEverything gets displayed correctly.'; | 10 var LONGER_CONTENTS = 'It works!\nEverything gets displayed correctly.'; |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 82 | 82 |
| 83 function onReadFileRequested(options, onSuccess, onError) { | 83 function onReadFileRequested(options, onSuccess, onError) { |
| 84 if (!openedFiles[options.openRequestId]) { | 84 if (!openedFiles[options.openRequestId]) { |
| 85 onError('INVALID_OPERATION'); | 85 onError('INVALID_OPERATION'); |
| 86 return; | 86 return; |
| 87 } | 87 } |
| 88 | 88 |
| 89 var contents = | 89 var contents = |
| 90 METADATA[openedFiles[options.openRequestId]].contents; | 90 METADATA[openedFiles[options.openRequestId]].contents; |
| 91 | 91 |
| 92 var length = contents.length - options.offset; | |
| 93 if (length < 0) { | |
| 94 length = 0; | |
| 95 } | |
| 96 if (length > options.length) { | |
| 97 length = options.length; | |
| 98 } | |
|
mtomasz
2017/05/29 07:10:17
I think we could simplify:
var remaining = Math.m
tetsui
2017/05/29 07:22:37
Done.
| |
| 99 | |
| 92 // Write the contents as ASCII text. | 100 // Write the contents as ASCII text. |
| 93 var buffer = new ArrayBuffer(options.length); | 101 var buffer = new ArrayBuffer(length); |
| 94 var bufferView = new Uint8Array(buffer); | 102 var bufferView = new Uint8Array(buffer); |
| 95 for (var i = 0; i < options.length; i++) { | 103 for (var i = 0; i < length; i++) { |
| 96 bufferView[i] = contents.charCodeAt(i); | 104 bufferView[i] = contents.charCodeAt(i + options.offset); |
| 97 } | 105 } |
| 98 | 106 |
| 99 onSuccess(buffer, false /* Last call. */); | 107 onSuccess(buffer, false /* Last call. */); |
| 100 } | 108 } |
| 101 | 109 |
| 102 function onMountRequested(onSuccess, onError) { | 110 function onMountRequested(onSuccess, onError) { |
| 103 chrome.fileSystemProvider.mount( | 111 chrome.fileSystemProvider.mount( |
| 104 {fileSystemId: 'sample-file-system', displayName: 'Sample File System'}, | 112 {fileSystemId: 'sample-file-system', displayName: 'Sample File System'}, |
| 105 function() { | 113 function() { |
| 106 if (chrome.runtime.lastError) { | 114 if (chrome.runtime.lastError) { |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 130 chrome.fileSystemProvider.onGetMetadataRequested.addListener( | 138 chrome.fileSystemProvider.onGetMetadataRequested.addListener( |
| 131 onGetMetadataRequested); | 139 onGetMetadataRequested); |
| 132 chrome.fileSystemProvider.onReadDirectoryRequested.addListener( | 140 chrome.fileSystemProvider.onReadDirectoryRequested.addListener( |
| 133 onReadDirectoryRequested); | 141 onReadDirectoryRequested); |
| 134 chrome.fileSystemProvider.onOpenFileRequested.addListener(onOpenFileRequested); | 142 chrome.fileSystemProvider.onOpenFileRequested.addListener(onOpenFileRequested); |
| 135 chrome.fileSystemProvider.onCloseFileRequested.addListener( | 143 chrome.fileSystemProvider.onCloseFileRequested.addListener( |
| 136 onCloseFileRequested); | 144 onCloseFileRequested); |
| 137 chrome.fileSystemProvider.onReadFileRequested.addListener(onReadFileRequested); | 145 chrome.fileSystemProvider.onReadFileRequested.addListener(onReadFileRequested); |
| 138 chrome.fileSystemProvider.onMountRequested.addListener(onMountRequested); | 146 chrome.fileSystemProvider.onMountRequested.addListener(onMountRequested); |
| 139 chrome.fileSystemProvider.onUnmountRequested.addListener(onUnmountRequested); | 147 chrome.fileSystemProvider.onUnmountRequested.addListener(onUnmountRequested); |
| OLD | NEW |