Permalink
Browse files

Use Buffer.byteLength(chunk) instead of chunk.length to avoid Out of …

…bounds errors.
  • Loading branch information...
1 parent e62a8e2 commit 9c9569388d519d4c4aa720d5eecf02df89b89093 @slaskis slaskis committed Jul 5, 2011
Showing with 1 addition and 1 deletion.
  1. +1 −1 lib/utils.js
View
@@ -21,7 +21,7 @@ exports.buffer = function buffer(type,path,stream,output){
stream.setEncoding(mime.charsets.lookup(mimeType))
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("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(){
try {
var data = parse(type,buf,len) || parse(mimeType,buf,len) || parse.default(buf,len);

0 comments on commit 9c95693

Please sign in to comment.