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

Unified Diff: chrome/browser/resources/file_manager/js/byte_reader.js

Issue 8748004: More accurate EXIF parsing (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Created 9 years, 1 month 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 | chrome/browser/resources/file_manager/js/exif_parser.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/resources/file_manager/js/byte_reader.js
diff --git a/chrome/browser/resources/file_manager/js/byte_reader.js b/chrome/browser/resources/file_manager/js/byte_reader.js
index 99121ae2d2d4a1dba24715ef9bce3caee77d906c..cf0276c76b76f08d3d8044fbd134f14a82e14330 100644
--- a/chrome/browser/resources/file_manager/js/byte_reader.js
+++ b/chrome/browser/resources/file_manager/js/byte_reader.js
@@ -2,9 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-ByteReader = function(arrayBuffer) {
- this.buf_ = arrayBuffer;
- this.view_ = new DataView(arrayBuffer);
+ByteReader = function(arrayBuffer, opt_offset, opt_length) {
+ opt_offset = opt_offset || 0;
+ opt_length = opt_length || (arrayBuffer.byteLength - opt_offset);
+ this.view_ = new DataView(arrayBuffer, opt_offset, opt_length);
this.pos_ = 0;
this.seekStack_ = [];
this.setByteOrder(ByteReader.BIG_ENDIAN);
@@ -144,6 +145,13 @@ ByteReader.readImage = function(dataView, pos, size, opt_end) {
// Instance methods.
/**
+ * Return true if the requested number of bytes can be read from the buffer.
+ */
+ByteReader.prototype.canRead = function(size) {
+ return this.pos_ + size <= this.view_.byteLength;
+},
+
+/**
* Return true if the current position is past the end of the buffer.
*/
ByteReader.prototype.eof = function() {
@@ -158,7 +166,7 @@ ByteReader.prototype.bof = function() {
};
/**
- * Return true if the current position is oustide the buffer.
+ * Return true if the current position is outside the buffer.
*/
ByteReader.prototype.beof = function() {
return this.pos_ >= this.view_.byteLength || this.pos_ < 0;
@@ -263,7 +271,8 @@ ByteReader.prototype.readSlice = function(size, opt_end,
this.validateRead(width, opt_end);
var arrayConstructor = opt_arrayConstructor || Uint8Array;
- var slice = new arrayConstructor(this.buf_, this.pos_, size);
+ var slice = new arrayConstructor(
+ this.view_.buffer, this.view_.byteOffset + this.pos, size);
this.pos_ += size;
return slice;
@@ -309,7 +318,7 @@ ByteReader.prototype.seek = function(pos, opt_seekStart, opt_end) {
newPos = pos;
}
- if (newPos < 0 || newPos >= this.view_.byteLength)
+ if (newPos < 0 || newPos > this.view_.byteLength)
throw new Error('Seek outside of buffer: ' + (newPos - opt_end));
this.pos_ = newPos;
« no previous file with comments | « no previous file | chrome/browser/resources/file_manager/js/exif_parser.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698