From ea0453f106ecdb98e43bdfb8a0fa2c4cfb009f06 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Sun, 18 May 2014 00:31:47 +0200 Subject: [PATCH] Add isEmpty method to Stream, DecodeStream and ChunkedStream --- src/core/chunked_stream.js | 4 ++++ src/core/stream.js | 11 ++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/core/chunked_stream.js b/src/core/chunked_stream.js index 6c0c16db0..8e402172f 100644 --- a/src/core/chunked_stream.js +++ b/src/core/chunked_stream.js @@ -133,6 +133,10 @@ var ChunkedStream = (function ChunkedStreamClosure() { return this.end - this.start; }, + get isEmpty() { + return this.length === 0; + }, + getByte: function ChunkedStream_getByte() { var pos = this.pos; if (pos >= this.end) { diff --git a/src/core/stream.js b/src/core/stream.js index a7d5d3456..f2996a66b 100644 --- a/src/core/stream.js +++ b/src/core/stream.js @@ -35,6 +35,9 @@ var Stream = (function StreamClosure() { get length() { return this.end - this.start; }, + get isEmpty() { + return this.length === 0; + }, getByte: function Stream_getByte() { if (this.pos >= this.end) { return -1; @@ -128,6 +131,12 @@ var DecodeStream = (function DecodeStreamClosure() { } DecodeStream.prototype = { + get isEmpty() { + while (!this.eof && this.bufferLength === 0) { + this.readBlock(); + } + return this.bufferLength === 0; + }, ensureBuffer: function DecodeStream_ensureBuffer(requested) { var buffer = this.buffer; var current; @@ -213,7 +222,7 @@ var DecodeStream = (function DecodeStreamClosure() { } return new Stream(this.buffer, start, length, dict); }, - skip: function Stream_skip(n) { + skip: function DecodeStream_skip(n) { if (!n) { n = 1; }