Skip to content

Commit

Permalink
Use Buffer.byteLength(chunk) instead of chunk.length to avoid Out of …
Browse files Browse the repository at this point in the history
…bounds errors.
  • Loading branch information
slaskis committed Jul 5, 2011
1 parent e62a8e2 commit 9c95693
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/utils.js
Expand Up @@ -21,7 +21,7 @@ exports.buffer = function buffer(type,path,stream,output){
stream.setEncoding(mime.charsets.lookup(mimeType)) stream.setEncoding(mime.charsets.lookup(mimeType))
stream.on("error",function(err){ error(output, err); }) // TODO Close the stream on error? stream.on("error",function(err){ error(output, err); }) // TODO Close the stream on error?
stream.on("timeout",function(){ error(output,new Error("[OpenURI] Connection timed out.")); }) // TODO Close the stream on timeout? stream.on("timeout",function(){ error(output,new Error("[OpenURI] Connection timed out.")); }) // TODO Close the stream on timeout?
stream.on("data",function(chunk){ buf.push(chunk); len += chunk.length; }) stream.on("data",function(chunk){ buf.push(chunk); len += Buffer.byteLength(chunk); })
stream.on("end",function(){ stream.on("end",function(){
try { try {
var data = parse(type,buf,len) || parse(mimeType,buf,len) || parse.default(buf,len); var data = parse(type,buf,len) || parse(mimeType,buf,len) || parse.default(buf,len);
Expand Down

0 comments on commit 9c95693

Please sign in to comment.