Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > How do I write binary data to a file with javascript & WSH?

Reply
Thread Tools

How do I write binary data to a file with javascript & WSH?

 
 
Billy Smith
Guest
Posts: n/a
 
      04-23-2006
I'm trying to write a little utility that will write some
binary data to a file via a javascript and Windows Script Host
under Windows XP. The only way to do this that I can find
is to convert the binary data to text via String.fromCharCode()
function and then write to the file with TextStream.Write().

But that function gives an "invalid parameter" error message
when I try to write some ASCII codes to the file. I could
understand if it refused to write any of the extended ASCII
characters but it accepts some and not others. For example
it will write characters with codes 157, 255, and 188 but
fails on 156 and 128, both of which are printable characters.
It works with ordinary characters (codes 0-127) just fine.

1) Why is it letting me write some extended ASCII characters and
not others?

2) It's beginning to look to me like javascript and WSH don't
provide a way to write binary data. Am I right or is there
a way to write binary data to a file using these tools?

Thanks,
Billy


 
Reply With Quote
 
 
 
 
Lasse Reichstein Nielsen
Guest
Posts: n/a
 
      04-23-2006
"Billy Smith" <> writes:

> I'm trying to write a little utility that will write some
> binary data to a file via a javascript and Windows Script Host
> under Windows XP. The only way to do this that I can find
> is to convert the binary data to text via String.fromCharCode()
> function and then write to the file with TextStream.Write().
>
> But that function gives an "invalid parameter" error message
> when I try to write some ASCII codes to the file. I could
> understand if it refused to write any of the extended ASCII
> characters but it accepts some and not others. For example
> it will write characters with codes 157, 255, and 188 but
> fails on 156 and 128, both of which are printable characters.


Neither 128 nor 156 are ASCII characters, nor are they defined in
ISO-8859-1. In Unicode, those code points are control characters
(128 is apparently an undefined control character, and 156 is
"single character introducer").

Apparently textual output of these code points fails.

You should also be aware that code point 128 is not represented
as one byte using UTF-8 encoding (or any other standardized
encoding of Unicode), so even if it can be written, it won't give
you what you want.

> It works with ordinary characters (codes 0-127) just fine.


As it should, these are Unicode characters as well.

> 2) It's beginning to look to me like javascript and WSH don't
> provide a way to write binary data. Am I right or is there
> a way to write binary data to a file using these tools?


There is nothing in Javascript itself. I don't know the capabilities
of WSH. But a Google on "wsh write binary file" seems useful.

/L
--
Lasse Reichstein Nielsen -
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
 
Reply With Quote
 
 
 
 
Billy Smith
Guest
Posts: n/a
 
      04-23-2006
OK, I guess I'm not thinking in terms of the correct encoding. I'll
go learn about the encoding javascript uses. Thanks.


"Lasse Reichstein Nielsen" <> wrote in message
news:...
> "Billy Smith" <> writes:
>
>> I'm trying to write a little utility that will write some
>> binary data to a file via a javascript and Windows Script Host
>> under Windows XP. The only way to do this that I can find
>> is to convert the binary data to text via String.fromCharCode()
>> function and then write to the file with TextStream.Write().
>>
>> But that function gives an "invalid parameter" error message
>> when I try to write some ASCII codes to the file. I could
>> understand if it refused to write any of the extended ASCII
>> characters but it accepts some and not others. For example
>> it will write characters with codes 157, 255, and 188 but
>> fails on 156 and 128, both of which are printable characters.

>
> Neither 128 nor 156 are ASCII characters, nor are they defined in
> ISO-8859-1. In Unicode, those code points are control characters
> (128 is apparently an undefined control character, and 156 is
> "single character introducer").
>
> Apparently textual output of these code points fails.
>
> You should also be aware that code point 128 is not represented
> as one byte using UTF-8 encoding (or any other standardized
> encoding of Unicode), so even if it can be written, it won't give
> you what you want.
>
>> It works with ordinary characters (codes 0-127) just fine.

>
> As it should, these are Unicode characters as well.
>
>> 2) It's beginning to look to me like javascript and WSH don't
>> provide a way to write binary data. Am I right or is there
>> a way to write binary data to a file using these tools?

>
> There is nothing in Javascript itself. I don't know the capabilities
> of WSH. But a Google on "wsh write binary file" seems useful.
>
> /L
> --
> Lasse Reichstein Nielsen -
> DHTML Death Colors:
> <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
> 'Faith without judgement merely degrades the spirit divine.'



 
Reply With Quote
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      04-23-2006
Lasse Reichstein Nielsen wrote:

> "Billy Smith" <> writes:
>> I'm trying to write a little utility that will write some
>> binary data to a file via a javascript and Windows Script Host
>> under Windows XP. The only way to do this that I can find
>> is to convert the binary data to text via String.fromCharCode()
>> function and then write to the file with TextStream.Write().
>>
>> But that function gives an "invalid parameter" error message
>> when I try to write some ASCII codes to the file. I could
>> understand if it refused to write any of the extended ASCII
>> characters but it accepts some and not others. For example
>> it will write characters with codes 157, 255, and 188 but
>> fails on 156 and 128, both of which are printable characters.

>
> Neither 128 nor 156 are ASCII characters, nor are they defined in
> ISO-8859-1. In Unicode, those code points are control characters
> (128 is apparently an undefined control character, and 156 is
> "single character introducer").
>
> Apparently textual output of these code points fails.
>
> You should also be aware that code point 128 is not represented
> as one byte using UTF-8 encoding (or any other standardized
> encoding of Unicode), so even if it can be written, it won't give
> you what you want.


I agree with all what you said, but not with the wording. A *code point*
is a coordinate, an _integer number_ (usually given in hexadecimal). It
is _not_ a character. It /specifies/ the _position of a character_,
therefore /identifies/ that character, in a character set (here: the
Unicode character set). The character requires encoding to be represented,
which is performed according to its code point.

So it would be correct to say that characters at certain code points of a
character set are control characters, and that a character at a certain
code point is not encoded in a certain way using a certain encoding
(here: UTF-.

<URL:http://en.wikipedia.org/wiki/Code_point>


PointedEars
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Program to open a file in binary, skip X bytes and write the rest ofthe file to a new file scad C++ 4 05-28-2009 08:47 AM
Re: How to write binary data to file and socket Steve Holden Python 0 12-12-2008 01:22 PM
How to write binary data to a file using buffer? Lambda C++ 1 06-06-2008 07:56 AM
Very strange problem using FWRITE() to write data to a binary file leonecla@yahoo.it C Programming 6 02-09-2005 06:06 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57