Permalink
Browse files

Bug fix and test case for streaming data that is longer than bufferSize

  • Loading branch information...
davetodd committed Nov 24, 2010
1 parent f951ca4 commit 2e78c028c1c934b7129c461143020ee10f4c5fc5
Showing with 18 additions and 3 deletions.
  1. +4 −3 grasshopper/lib/ghp.js
  2. +6 −0 test/fixtures/ghp/too_big.txt
  3. +8 −0 test/simple/ghp-test.js
View
@@ -158,10 +158,11 @@ Streamer.prototype.write = function(str) {
while(this._bufContentLen +
(tmpBuffer.length - currentOffset) >= bufferSize) {
+ var remaining = bufferSize - this._bufContentLen;
tmpBuffer.copy(this._out, this._bufContentLen, currentOffset,
- currentOffset + bufferSize);
- currentOffset += bufferSize;
- this._bufContentLen += bufferSize;
+ currentOffset + remaining);
+ currentOffset += remaining;
+ this._bufContentLen += remaining;
this.flush();
}
@@ -0,0 +1,6 @@
+offset<%
+var tooBig = '';
+for (var i = 0; i <= 8200; i++) {
+ tooBig += 'A';
+}
+%><%=tooBig%>
View
@@ -71,6 +71,14 @@ suite.tests = {
assert.equal(response.out, '\n');
assert.ok(response.ended);
next();
+ },
+
+ 'Too big template' : function(next) {
+ var response = new MockResponse();
+ ghp.fill('../fixtures/ghp/too_big.txt', response, {}, 'utf8', '../fixtures/ghp', 'txt');
+ assert.equal(response.out.length, 8207);
+ assert.ok(response.ended);
+ next();
}
};

0 comments on commit 2e78c02

Please sign in to comment.