Re: Binary File I/O
- From: "Julian Turner" <julian@xxxxxxxxxxxxxx>
- Date: 15 Nov 2005 03:59:04 -0800
Patient Guy wrote:
> The problem is step (2). I have not toyed with core Javascript
> sufficiently to know if binary data sequences can be manipulated. They
> certainly cannot be manipulated using Strings. It is possible that they
> can be manipulated as Array objects (with Unicode elements? Number-type
> elements?).
> If someone has had some success in this area, I would appreciate knowing,
> so that my time spent in experimentation is reduced (and possibly not even
> wasted).
Hi
The ECMA script specification (and both JScript or Javascript) does not
have a specific data type for handling bytes as such. The only types
explicitly available to help are Numbers and Strings.
But ECMA can easily process arrays of values in the range 0-255 using
the Javascript Array object and Number type.
Accordingly, the main option is to have an Array of Number types. I.e.
each item in the Array holds a value 0-255 representing a byte. There
are a range of bitwise operators in the language to manipulate the data
from there (<< >> >>> & | ^ etc).
It is not the most efficient, by I have implemented base64 encoding,
utf-8 encoding, and huffman compression using this method (albeit slow
for files over about 100k).
String objects can also be used in this respect Each character can
hold values from 0-255 (as well as unicode values up to 65535, although
these can be ignored for these purposes). Of course not all of these
values are printable, but within the String type they can be
manipulated. You can access the 0-255 value using either
String.charCodeAt(i).
An alternative could be to create a Java applet to do the binary
manipulations, and I am looking at that myself.
[snip]
> I want to do some testing using files as well, so the file I/O read() and
> write() functions must do something other than using or returning String
> objects. One post I read elsewhere talked of trying to deal with I/O and
> binary data in chunks of long numbers: so does does code like:
[snip]
In your post to comp.lang.javascript I gave you my experiences in using
the Scripting.FileSystemObject. For IE at least, I have sucessfully
carried out binary I/0, using a combination of JScript and VBScript.
There is no common cross browser solution. Each browser has (or does
not have) its own file handling components.
Regards
Julian
.
- References:
- Binary File I/O
- From: Patient Guy
- Binary File I/O
- Prev by Date: Binary File I/O
- Next by Date: Re: To know Page Load is over
- Previous by thread: Binary File I/O
- Next by thread: Re: Binary File I/O
- Index(es):
Relevant Pages
|