javascript - buffer.js:246 "Object 1 has no method 'toLowerCase' -


i m trying make .smil (.xml) parser in javascript. when want test it, node.js me that:

buffer.js:246     switch(encoding && encoding.tolowercase()){                                 ^ typeerror: object 1 has no method 'tolowercase'     @ function.buffer.isencoding (buffer.js:246:32)     @ assertencoding (fs.js:98:27)     @ object.fsread (fs.js:422:5)     @ gets (/home/pi/smil_parser.js:8:8)     @ read_until (/home/pi/smil_parser.js:28:14)     @ home/pi/smil_parser.js:64:14     @ object.oncomplete (fs.js:93.15) 

gets () indeed 1 of function:

var io=require('fs'); ... function gets (file){     var chaine="", cache="", pkmn=0;     io.read(file, cache, 0, 1, null, function(err, byte, buf){         if (err || byte===0){return -1;}         while ((cache!=="\n"))         {             chaine=chaine+cache;             cache="";             pkmn=io.readsync(file, cache, 0, 1, null);             if (pkmn===0){return -1;}         }     }); } 

i don t have idea of go wrong, seem read, ve made sure right arguments, tried update node.js, fs , npm. , similar error found on google update problem.

edit: added complete error message, here function read_until:

function read_until(smil, limit){     var line="";         {         line=gets(smil);         if (line===-1){return -1}     }while (!(line.search(limit)));     return 0; } 

.

function parse (pathname){     var smil=0, line="", pkmn=0;     io.open(pathname, 'r', function (err, fd){         if (err){return -1;}         smil=fd;         pkmn=read_until(smil, "<smil>");         ... 

fs.read takes buffer not string.

change cache buffer.

function gets (file){     var chaine="", cache=new buffer(), pkmn=0;     io.read(file, cache, 0, 1, null, function(err, byte, buf){         if (err || byte===0){return -1;}         while ((cache!=="\n"))         {             chaine=chaine+cache;             cache="";             pkmn=io.readsync(file, cache, 0, 1, null);             if (pkmn===0){return -1;}         }     }); } 

see fs.read code here

if want use string "buffer" must use legacy interface

legacy string interface fs.read(fd, length, position, encoding, callback)


Comments

Popular posts from this blog

How to logout from a login page in asp.net -

Stack level too deep error after upgrade to rails 3.2 and ruby 1.9.3 -