473,837 Members | 1,536 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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.fromChar Code()
function and then write to the file with TextStream.Writ e().

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
Apr 23 '06 #1
3 8545
"Billy Smith" <za*********@ya hoo.com> 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.fromChar Code()
function and then write to the file with TextStream.Writ e().

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 - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'
Apr 23 '06 #2
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" <lr*@hotpop.com > wrote in message
news:y7******** **@hotpop.com.. .
"Billy Smith" <za*********@ya hoo.com> 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.fromChar Code()
function and then write to the file with TextStream.Writ e().

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 - lr*@hotpop.com
DHTML Death Colors:
<URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'

Apr 23 '06 #3
Lasse Reichstein Nielsen wrote:
"Billy Smith" <za*********@ya hoo.com> 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.fromChar Code()
function and then write to the file with TextStream.Writ e().

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-8).

<URL:http://en.wikipedia.or g/wiki/Code_point>
PointedEars
Apr 23 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
15677
by: kee | last post by:
Hi All, I am trying to write binary data to a file, which is bmp image: Open "d:\temp\test001.bmp" For Binary Access Write As #1 Put #1, 1, strImage Close #1 *** strImage contains binary data
4
11170
by: Tom Van Ginneken | last post by:
Hi, I need to write binary data to a serial port. I am using this function: #include <unistd.h> ssize_t write(int fd, const void *buf, size_t count); I am able to write a alpha-numeric character to the port using this: write (filedescriptor,"a",1);
0
380
by: gauravkhanna | last post by:
Hi All I need some help for the below problem: Scenario We need to send large binary files (audio file of about 10 MB or so) from the client machine (.Net Windows based application, located outside the home network) to the Web Server and then retrieve the file back from the web server to the client.
7
2868
by: robert.differentone | last post by:
Hi, Does anybody know any javascript which converts images into binary data. Thanks in advance, R.
0
1905
by: magicbeans | last post by:
I am trying to create a .bin file of records from a .txt file. Initially the records are stored in a text file and I want to Read from the .txt file and Write to the .bin file. This is the C++ code. The result write exactly but it has funny-looking unwanted characters attached at the end of the .bin file. How do I fix it? #include <iostream> #include <fstream> using namespace std; struct details { int id;
2
3549
by: Thomi Aurel RUAG A | last post by:
Hy I'm using Python 2.4.2 on an ARM (PXA-270) platform (linux-2.6.17). My Goal is to write a list of bytes down to a file (opened in binary mode) in one cycle. The crux is that a '0x0a' (line feed) will break the cycle of one writing into several pieces. Writing to a "simple" file, this wouldn't cause any problem. Assuming - without questioning ;-) - that a device file (/dev/*) has to be written in one cycle because one write call will...
1
3909
by: =?Utf-8?B?U3RldmVU?= | last post by:
I have a structure that contains both 32x32 and 16x16 icons plus some text. I want to write all this to an XML file so that I can recover the icons later in an application. Can someone tell me how to properly serialize the System.Drawing.Icon structure to an XML file? The following code doesn't write the icon information to the xml file. private void CreateXmlFile(string filename) {
1
2051
by: xiao | last post by:
HI~ guys , I have a program here (Sorry it is very long about 240 lines.) It can read and write the header information successfully but it cannot write the array successfully. I guess there is something wrong with the Write2DArrayInt function there. Can any one henlp me to find it out? Thank you~ (BTW : The printf function in line 114 and 139 implys that the data is right, but after that , in the new generated file, the values are all...
1
3933
by: Sachin Garg | last post by:
I have a program which opens a fstream in binary input+output mode, creating the file if it doesn't exists. But writing doesn't works after reading, it must be something obvious that I am not aware of. f.open(filename,ios::in | ios::out | ios::binary | ios::trunc) The program flow is 1) write some data 2) read the data
0
9839
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10871
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10564
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9396
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7806
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6998
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5668
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5846
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3123
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.