Re: Learning OS.File
Neil <[email protected]> Fri, 19 Dec 2014 13:20:28 +0000
| Newsgroups | gmane.comp.mozilla.devel.xpfe |
|---|---|
| Message-ID | <[email protected]> |
[email protected] wrote: >I think my problem is that I'm so used to working with nsIFile that I'm expecting OS.File to operate in the same manner. Specifically, nsIFile reads the file without automatically converting the data into another format. If the source file is text, then what is read in stays as text. With OS.File, the conversion of the text file into a typed array was throwing me off. > nsIFile doesn't actually read anything; my best guess is that you were using one of the line input streams. I don't know of any equivalent for OS.File. >Experimenting, I found the solution to be to decode the typed array to a text string then split the text string at the new lines (\n). This creates the array I wanted so that I can access the elements as needed later on. > >If you have a more efficient method of doing this, please(!) let me know. > > It's slightly more efficient to specify the encoding when you ask to read the file, as then the decoding is done off-main-thread too. -- Warning: May contain traces of nuts.