OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 15 matching lines...) Expand all Loading... |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 /** | 31 /** |
32 * @interface | 32 * @interface |
33 */ | 33 */ |
34 WebInspector.OutputStreamDelegate = function() | 34 WebInspector.OutputStreamDelegate = function() |
35 { | 35 { |
36 } | 36 }; |
37 | 37 |
38 WebInspector.OutputStreamDelegate.prototype = { | 38 WebInspector.OutputStreamDelegate.prototype = { |
39 onTransferStarted: function() { }, | 39 onTransferStarted: function() { }, |
40 | 40 |
41 onTransferFinished: function() { }, | 41 onTransferFinished: function() { }, |
42 | 42 |
43 /** | 43 /** |
44 * @param {!WebInspector.ChunkedReader} reader | 44 * @param {!WebInspector.ChunkedReader} reader |
45 */ | 45 */ |
46 onChunkTransferred: function(reader) { }, | 46 onChunkTransferred: function(reader) { }, |
47 | 47 |
48 /** | 48 /** |
49 * @param {!WebInspector.ChunkedReader} reader | 49 * @param {!WebInspector.ChunkedReader} reader |
50 * @param {!Event} event | 50 * @param {!Event} event |
51 */ | 51 */ |
52 onError: function(reader, event) { }, | 52 onError: function(reader, event) { }, |
53 } | 53 }; |
54 | 54 |
55 /** | 55 /** |
56 * @interface | 56 * @interface |
57 */ | 57 */ |
58 WebInspector.ChunkedReader = function() | 58 WebInspector.ChunkedReader = function() |
59 { | 59 { |
60 } | 60 }; |
61 | 61 |
62 WebInspector.ChunkedReader.prototype = { | 62 WebInspector.ChunkedReader.prototype = { |
63 /** | 63 /** |
64 * @return {number} | 64 * @return {number} |
65 */ | 65 */ |
66 fileSize: function() { }, | 66 fileSize: function() { }, |
67 | 67 |
68 /** | 68 /** |
69 * @return {number} | 69 * @return {number} |
70 */ | 70 */ |
71 loadedSize: function() { }, | 71 loadedSize: function() { }, |
72 | 72 |
73 /** | 73 /** |
74 * @return {string} | 74 * @return {string} |
75 */ | 75 */ |
76 fileName: function() { }, | 76 fileName: function() { }, |
77 | 77 |
78 cancel: function() { } | 78 cancel: function() { } |
79 } | 79 }; |
80 | 80 |
81 /** | 81 /** |
82 * @constructor | 82 * @constructor |
83 * @implements {WebInspector.ChunkedReader} | 83 * @implements {WebInspector.ChunkedReader} |
84 * @param {!File} file | 84 * @param {!File} file |
85 * @param {number} chunkSize | 85 * @param {number} chunkSize |
86 * @param {!WebInspector.OutputStreamDelegate} delegate | 86 * @param {!WebInspector.OutputStreamDelegate} delegate |
87 */ | 87 */ |
88 WebInspector.ChunkedFileReader = function(file, chunkSize, delegate) | 88 WebInspector.ChunkedFileReader = function(file, chunkSize, delegate) |
89 { | 89 { |
90 this._file = file; | 90 this._file = file; |
91 this._fileSize = file.size; | 91 this._fileSize = file.size; |
92 this._loadedSize = 0; | 92 this._loadedSize = 0; |
93 this._chunkSize = chunkSize; | 93 this._chunkSize = chunkSize; |
94 this._delegate = delegate; | 94 this._delegate = delegate; |
95 this._decoder = new TextDecoder(); | 95 this._decoder = new TextDecoder(); |
96 this._isCanceled = false; | 96 this._isCanceled = false; |
97 } | 97 }; |
98 | 98 |
99 WebInspector.ChunkedFileReader.prototype = { | 99 WebInspector.ChunkedFileReader.prototype = { |
100 /** | 100 /** |
101 * @param {!WebInspector.OutputStream} output | 101 * @param {!WebInspector.OutputStream} output |
102 */ | 102 */ |
103 start: function(output) | 103 start: function(output) |
104 { | 104 { |
105 this._output = output; | 105 this._output = output; |
106 | 106 |
107 this._reader = new FileReader(); | 107 this._reader = new FileReader(); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 this._loadChunk(); | 177 this._loadChunk(); |
178 }, | 178 }, |
179 | 179 |
180 _loadChunk: function() | 180 _loadChunk: function() |
181 { | 181 { |
182 var chunkStart = this._loadedSize; | 182 var chunkStart = this._loadedSize; |
183 var chunkEnd = Math.min(this._fileSize, chunkStart + this._chunkSize); | 183 var chunkEnd = Math.min(this._fileSize, chunkStart + this._chunkSize); |
184 var nextPart = this._file.slice(chunkStart, chunkEnd); | 184 var nextPart = this._file.slice(chunkStart, chunkEnd); |
185 this._reader.readAsArrayBuffer(nextPart); | 185 this._reader.readAsArrayBuffer(nextPart); |
186 } | 186 } |
187 } | 187 }; |
188 | 188 |
189 /** | 189 /** |
190 * @param {function(!File)} callback | 190 * @param {function(!File)} callback |
191 * @return {!Node} | 191 * @return {!Node} |
192 */ | 192 */ |
193 WebInspector.createFileSelectorElement = function(callback) | 193 WebInspector.createFileSelectorElement = function(callback) |
194 { | 194 { |
195 var fileSelectorElement = createElement("input"); | 195 var fileSelectorElement = createElement("input"); |
196 fileSelectorElement.type = "file"; | 196 fileSelectorElement.type = "file"; |
197 fileSelectorElement.style.display = "none"; | 197 fileSelectorElement.style.display = "none"; |
198 fileSelectorElement.setAttribute("tabindex", -1); | 198 fileSelectorElement.setAttribute("tabindex", -1); |
199 fileSelectorElement.onchange = onChange; | 199 fileSelectorElement.onchange = onChange; |
200 function onChange(event) | 200 function onChange(event) |
201 { | 201 { |
202 callback(fileSelectorElement.files[0]); | 202 callback(fileSelectorElement.files[0]); |
203 } | 203 } |
204 return fileSelectorElement; | 204 return fileSelectorElement; |
205 } | 205 }; |
206 | 206 |
207 /** | 207 /** |
208 * @constructor | 208 * @constructor |
209 * @implements {WebInspector.OutputStream} | 209 * @implements {WebInspector.OutputStream} |
210 */ | 210 */ |
211 WebInspector.FileOutputStream = function() | 211 WebInspector.FileOutputStream = function() |
212 { | 212 { |
213 } | 213 }; |
214 | 214 |
215 WebInspector.FileOutputStream.prototype = { | 215 WebInspector.FileOutputStream.prototype = { |
216 /** | 216 /** |
217 * @param {string} fileName | 217 * @param {string} fileName |
218 * @param {function(boolean)} callback | 218 * @param {function(boolean)} callback |
219 */ | 219 */ |
220 open: function(fileName, callback) | 220 open: function(fileName, callback) |
221 { | 221 { |
222 this._closed = false; | 222 this._closed = false; |
223 this._writeCallbacks = []; | 223 this._writeCallbacks = []; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 var callback = this._writeCallbacks.shift(); | 269 var callback = this._writeCallbacks.shift(); |
270 if (callback) | 270 if (callback) |
271 callback(this); | 271 callback(this); |
272 if (!this._writeCallbacks.length) { | 272 if (!this._writeCallbacks.length) { |
273 if (this._closed) { | 273 if (this._closed) { |
274 WebInspector.fileManager.removeEventListener(WebInspector.FileMa
nager.Events.AppendedToURL, this._onAppendDone, this); | 274 WebInspector.fileManager.removeEventListener(WebInspector.FileMa
nager.Events.AppendedToURL, this._onAppendDone, this); |
275 WebInspector.fileManager.close(this._fileName); | 275 WebInspector.fileManager.close(this._fileName); |
276 } | 276 } |
277 } | 277 } |
278 } | 278 } |
279 } | 279 }; |
OLD | NEW |