| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 function ByteReader(arrayBuffer, opt_offset, opt_length) { | 5 function ByteReader(arrayBuffer, opt_offset, opt_length) { |
| 6 opt_offset = opt_offset || 0; | 6 opt_offset = opt_offset || 0; |
| 7 opt_length = opt_length || (arrayBuffer.byteLength - opt_offset); | 7 opt_length = opt_length || (arrayBuffer.byteLength - opt_offset); |
| 8 this.view_ = new DataView(arrayBuffer, opt_offset, opt_length); | 8 this.view_ = new DataView(arrayBuffer, opt_offset, opt_length); |
| 9 this.pos_ = 0; | 9 this.pos_ = 0; |
| 10 this.seekStack_ = []; | 10 this.seekStack_ = []; |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 return 'data:image/' + mime + ';base64,' + b64; | 174 return 'data:image/' + mime + ';base64,' + b64; |
| 175 }; | 175 }; |
| 176 | 176 |
| 177 // Instance methods. | 177 // Instance methods. |
| 178 | 178 |
| 179 /** | 179 /** |
| 180 * Return true if the requested number of bytes can be read from the buffer. | 180 * Return true if the requested number of bytes can be read from the buffer. |
| 181 */ | 181 */ |
| 182 ByteReader.prototype.canRead = function(size) { | 182 ByteReader.prototype.canRead = function(size) { |
| 183 return this.pos_ + size <= this.view_.byteLength; | 183 return this.pos_ + size <= this.view_.byteLength; |
| 184 }, | 184 }; |
| 185 | 185 |
| 186 /** | 186 /** |
| 187 * Return true if the current position is past the end of the buffer. | 187 * Return true if the current position is past the end of the buffer. |
| 188 */ | 188 */ |
| 189 ByteReader.prototype.eof = function() { | 189 ByteReader.prototype.eof = function() { |
| 190 return this.pos_ >= this.view_.byteLength; | 190 return this.pos_ >= this.view_.byteLength; |
| 191 }; | 191 }; |
| 192 | 192 |
| 193 /** | 193 /** |
| 194 * Return true if the current position is before the beginning of the buffer. | 194 * Return true if the current position is before the beginning of the buffer. |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 | 247 |
| 248 default: | 248 default: |
| 249 throw new Error('Invalid width: ' + width); | 249 throw new Error('Invalid width: ' + width); |
| 250 break; | 250 break; |
| 251 } | 251 } |
| 252 | 252 |
| 253 this.validateRead(width, opt_end); | 253 this.validateRead(width, opt_end); |
| 254 var rv = this.view_[method](this.pos_, this.littleEndian_); | 254 var rv = this.view_[method](this.pos_, this.littleEndian_); |
| 255 this.pos_ += width; | 255 this.pos_ += width; |
| 256 return rv; | 256 return rv; |
| 257 } | 257 }; |
| 258 | 258 |
| 259 /** | 259 /** |
| 260 * Read as a sequence of characters, returning them as a single string. | 260 * Read as a sequence of characters, returning them as a single string. |
| 261 * | 261 * |
| 262 * Adjusts the current position on success. Throws an exception if the | 262 * Adjusts the current position on success. Throws an exception if the |
| 263 * read would go past the end of the buffer. | 263 * read would go past the end of the buffer. |
| 264 */ | 264 */ |
| 265 ByteReader.prototype.readString = function(size, opt_end) { | 265 ByteReader.prototype.readString = function(size, opt_end) { |
| 266 var rv = ByteReader.readString(this.view_, this.pos_, size, opt_end); | 266 var rv = ByteReader.readString(this.view_, this.pos_, size, opt_end); |
| 267 this.pos_ += size; | 267 this.pos_ += size; |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 403 ByteReader.prototype.popSeek = function() { | 403 ByteReader.prototype.popSeek = function() { |
| 404 this.seek(this.seekStack_.pop()); | 404 this.seek(this.seekStack_.pop()); |
| 405 }; | 405 }; |
| 406 | 406 |
| 407 /** | 407 /** |
| 408 * Return the current read position. | 408 * Return the current read position. |
| 409 */ | 409 */ |
| 410 ByteReader.prototype.tell = function() { | 410 ByteReader.prototype.tell = function() { |
| 411 return this.pos_; | 411 return this.pos_; |
| 412 }; | 412 }; |
| OLD | NEW |