Skip to content

Commit

Permalink
Fix typed array output
Browse files Browse the repository at this point in the history
  • Loading branch information
devongovett committed Feb 15, 2015
1 parent f4fb95e commit f69afbe
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
9 changes: 8 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,14 @@ function tinf_uncompress(source, dest) {

} while (!bfinal);

return d.dest.slice(0, d.destLen);
if (d.destLen < d.dest.length) {
if (typeof d.dest.slice === 'function')
return d.dest.slice(0, d.destLen);
else
return d.dest.subarray(0, d.destLen);
}

return d.dest;
}

/* -------------------- *
Expand Down
9 changes: 8 additions & 1 deletion test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,16 @@ describe('tiny-inflate', function() {
assert.deepEqual(out, uncompressed);
});

it('should handle uncompressed blocks', function() {
it('should handle fixed huffman blocks', function() {
var out = new Buffer(uncompressed.length);
inflate(fixed, out);
assert.deepEqual(out, uncompressed);
});

it('should handle typed arrays', function() {
var input = new Uint8Array(compressed);
var out = new Uint8Array(uncompressed.length);
inflate(input, out);
assert.deepEqual(out, new Uint8Array(uncompressed));
});
});

0 comments on commit f69afbe

Please sign in to comment.