[Jslib] Re: read() and readline()

Pete Collins pete@mozdev.org
Thu, 17 Jan 2002 10:00:07 -0500


basic wrote:

> What do people think about extending read() to take a parameter to read 
> the number of bytes instead of the whole file?
> 
> And maybe readline could support DOS/Windows newlines by using 
> split(/(?:\n\r)|[\n\r]/) rather than split(/[\n\r]/) ? ;-p
> 
> currently read and readline uses rv variable for return values. This is 
> okay for small chunks of data but when the return value is huge, it gets 
> copied lots of times, since js doesn't do string reference. I guess it 
> will get copied anyways, but using rv causes it to get copied one more 
> time.
> 
> I'm also wondering about have a read() method that returns an object 
> with a property that contains the data string, this way it doesn't get 
> copied as it returns a reference to the object. Not sure if that helps....
> 
> Is there a lib to load files via uri? like via ftp: http: file: ;-)


Yes, but not in jslib yet.  ;-)

You can read as many bytes as you want:

mInputStream.read(this.mFileInst.fileSize);

takes a bytes param.

You can have an optional param added to jslib read to
allow for bytes to read. Right now we use the total file size.

read(aOptionalBytes) . . .

You can check for the param and if it exists, make sure it doesn't
exceed the filesize bytes and use the optional size to pass to read.

Please, any help you can offer to jslib would be gladly appreciated.

;-)


Eric and myself haven't been able to do much lately.

Thanks basic!

--pete






> 
> basic