473,695 Members | 3,060 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Binary I/O in Javascript



Has anyone written code that successfully manipulates binary file data
using Javascript?

It might---and in the case of doing I/O, will---make use of browser-
specific functions (ActiveX/COM with Internet Explorer, XPCOM/XPConnect
with Mozilla/Firefox).

I am writing client-side code that will generate binary data for producing
a GIF file through an OBJECT element. (The GIF is an image of a line and
points on a two-axis plot.)

In order to do some tests to see how the OBJECT element performs, I am
trying to read in binary file data (using XPConnect functions in Firefox).

The problem is that plain Javascript and these browser-specific functions
will not marry with one another (for instance, they cannot be manipulated
as strings, and the read() functions of these things return strings as
well). This is from what little I know. Dated posted in various
newsgroups on the subject get comments saying that if those creating file
I/O libraries in client-side code for text file I/O might as well make it
possible for manipulating binary data in I/O, since the point of no return
is authorizing any access to the file system, and not whether it is text or
binary access.

If I don't get an answer here, I will take this to the JScript and XPCOM
groups, where I can hope for more from the latter than the former. If it
can't be done in MSIE though, I suppose I should forget it (and try to
write a plugin of some kind instead). Unless I hear that MSIE browsers are
being used by less than 100,000 people around the world.
Nov 23 '05 #1
26 4300
VK

Patient Guy wrote:
Has anyone written code that successfully manipulates binary file data
using Javascript?

It might---and in the case of doing I/O, will---make use of browser-
specific functions (ActiveX/COM with Internet Explorer, XPCOM/XPConnect
with Mozilla/Firefox).

I am writing client-side code that will generate binary data for producing
a GIF file through an OBJECT element. (The GIF is an image of a line and
points on a two-axis plot.)

In order to do some tests to see how the OBJECT element performs, I am
trying to read in binary file data (using XPConnect functions in Firefox).

The problem is that plain Javascript and these browser-specific functions
will not marry with one another (for instance, they cannot be manipulated
as strings, and the read() functions of these things return strings as
well). This is from what little I know. Dated posted in various
newsgroups on the subject get comments saying that if those creating file
I/O libraries in client-side code for text file I/O might as well make it
possible for manipulating binary data in I/O, since the point of no return
is authorizing any access to the file system, and not whether it is text or
binary access.

If I don't get an answer here, I will take this to the JScript and XPCOM
groups, where I can hope for more from the latter than the former. If it
can't be done in MSIE though, I suppose I should forget it (and try to
write a plugin of some kind instead). Unless I hear that MSIE browsers are
being used by less than 100,000 people around the world.


I'm doing my jsFileManager as universal FSO/XPConnect wrapper.
I'd really like to finish up the Gesko part by this week-end if I'll be
able to keep staying late after my main job. IE part is already done.

Briefly - yes, it is perfectly possible in the universal way (despite
the internal mechanics is as different as black and white, plus buggy
as a street dog from the Microsoft side at least).

jsFileManager will be free open library any way so if you have some
burning questions - I'm glad to try to answer.

Nov 23 '05 #2
VK
As an addon:
Actually my first realease planned to be text files reading/writing
plus lounch applications. Binary data reading/writing can be done
additionally as it really not a challenge.

Any file in the file system is binary in meaning that it consists of
bytes allocated in some sequences - either it's a text file or a
picture or an application - it doesn't matter. So you can read any file
as text or as binary.
TextStream differs from ByteStream only in usage of internal tokenizer.
This tokenizer makes TextStream tread differently line breaks and
special char sequences (if not ASCII encoding). Also reading goes from
one system line break to another.
So to handle ByteStream you simply need to read/write data by blocks of
bytes (say 80 bytes per block) not by lines. And you have to ensure
that the encoding set to base ASCII to avoid bytes transformations by
tokenizer. This is all real lore of byte I/O.

Nov 23 '05 #3
Patient Guy wrote:
Has anyone written code that successfully manipulates binary file data
using Javascript? It might---and in the case of doing I/O, will---make use of browser-
specific functions (ActiveX/COM with Internet Explorer, XPCOM/XPConnect
with Mozilla/Firefox).

[snip]

You can certainly manipulate binary data in a rough fashion, using a
Javascript String. A Javascript String format is in Unicode pairs I
believe. I.e. each character can hold a value from 0000 to FFFF, so
the binary stream could be represented either as a sequence where the
higher pair is 00, and the byte is the lower, i.e. 0000, 0001, 0002
.... 00FF, or each pair of bytes is encoded in to the Unicode pairs,
e.g. 0001, 0203, 0304, ... FEFF. The latter case is problematic for
odd numbered streams.

The trick however is getting the binary codes from files into and out
of the String object in the first place, whether at all, or
efficiently.

I have been experimenting myself, and so far Javascript alone does not
seem to be enough.

INTERNET EXPLORER

There are two ActiveX objects to consider:-

(a) Scripting.FileS ystemObject

Through Javascript, it seems to be impossible to use this to save
strings containing a binary stream. If encoding is set to ASCII, an
error will be thrown for char codes in the range 80 - A0 which you try
to write to a file. If encoding is Unicode, then the resulting file is
prefixed with FF FE, and it only works for even numbered streams.

You can use it to load binary into Strings, but you need again to
watch for characters 80-A0, as they are converted during the load
process to some other unicode characters. This is consistently done,
so once you know the conversion, i.e. 80->2030 etc, you can easily
reverse it.

However, oddly, in VBScript, with encoding set to ASCII you can
actually write binary using Scripting.FileS ystemObject. I think this
is because VBScript has other data types which are more acceptable to
the ActiveX object.

So you can adopt a mixture of VBScript and Javascript to get a kind of
binary i/o.

(a) ADODB.Stream

This gives full binary file system access. I think however it is
disabled by default on later versions of windows. In any event, it has
one limitation again in Javascript if you want to write binary data
from a String to the stream: the WriteText method again fails with
characters in the range 80-A0.

(c) XML dataType

A third area to explore is setting an XML node data type to bin.hex or
bin.base64. You could convert a String to base64 or hex, and set the
nodeTypedValue with that encoded string. This is more useful for
HTTPRequests, but conversion to base64 and hex is very slow. When you
subsequently bet the nodeTypedValue it will return a Variant byte
buffer containing the binary. Useless in Javascript, but might be
useable with ADODB.Stream or VBScript.

MOZILLA

I am not as familiar with the XPCOM components - see www.xulplanet.com,
but they may have some scriptable input and output streams. Again
don't know how they would interact with the Javascript String type.

Julian

Nov 23 '05 #4
On Mon, 14 Nov 2005 10:25:47 +0000 (UTC), Patient Guy
<Pa*********@no where.to.be.fou nd.com> wrote:
I am writing client-side code that will generate binary data for producing
a GIF file through an OBJECT element. (The GIF is an image of a line and
points on a two-axis plot.)


If your goal is generating a 2axis plot, why are you bothering to
generate a GIF? Just use the vector graphic methods available to
both IE and mozilla, and forget mucking around with GIF's.

Jim.
Nov 23 '05 #5
>>I am writing client-side code that will generate binary data for producing
a GIF file through an OBJECT element. (The GIF is an image of a line and
points on a two-axis plot.)


If your goal is generating a 2axis plot, why are you bothering to
generate a GIF? Just use the vector graphic methods available to
both IE and mozilla, and forget mucking around with GIF's.


Please elaborate, do you mean SVG ? As that requires a plug in.

There is Walter Zorn's div based JavaScript graphics :-

http://www.walterzorn.com/jsgraphics/jsgraphics_e.htm

Otherwise please do tell us the magic vector graphics methods :)

Aaron
Nov 23 '05 #6
JRS: In article <Xn************ ******@213.155. 197.138>, dated Mon, 14
Nov 2005 10:25:47, seen in news:comp.lang. javascript, Patient Guy
<Pa*********@no where.to.be.fou nd.com> posted :

Has anyone written code that successfully manipulates binary file data
using Javascript?


Not I; but you may care to know that <URL:http://www.merlyn.demon.co.uk/
js-misc0.htm#IEEE> shows some conversion between javascript Numbers and
equivalent more-ostensibly-binary forms.

--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.c om/faq/> JL/RC: FAQ of news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Nov 23 '05 #7
On Mon, 14 Nov 2005 23:15:36 -0000, "Aaron Gray"
<an********@gma il.com> wrote:
If your goal is generating a 2axis plot, why are you bothering to
generate a GIF? Just use the vector graphic methods available to
both IE and mozilla, and forget mucking around with GIF's.


Please elaborate, do you mean SVG ? As that requires a plug in.


VML or DirectAnimation in IE
Native SVG in Opera, FireFox 1.5 or Safari beta's
Canvas in Safari, Opera or ..
Flash or SVG plugins...

Jim.
Nov 23 '05 #8
Patient Guy wrote:
Has anyone written code that successfully manipulates binary file data
using Javascript?
What do you mean by manipulate? Concatenate segments? Add binary
numbers? Save or load to/from disk? Or ???
I am writing client-side code that will generate binary data for producing
a GIF file through an OBJECT element. (The GIF is an image of a line and
points on a two-axis plot.)


I'd like to help, but why do you need to pass binary data to a plot
object?

Just trying to get a grip on what you're after.

Kev

Nov 23 '05 #9
VK

Kevin wrote:
I'd like to help, but why do you need to pass binary data to a plot
object?


Just to use JavaScript (run in a browser) as an application platform I
guess. What's wrong in that?

And yes in many languages (not JavaScript only) a byte-in-byte
in's/out's transform into an idiotically complicated problem floating
around the same question: "How the hell to kill or at least to make it
shut up the build-in string tokenizer?!?"

A perfect sample is Java where you can *manually* form IP packets if
you need to, but you cannot send byte-in-byte sequence to say printer
w/o loosing time and the rest of your good mind.

Nov 23 '05 #10

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

Similar topics

17
5647
by: joealey2003 | last post by:
Hi all... I need to load an image, access it's content and render it. So, tried: <script type="text/javascript"> xmlHttp = new XMLHttpRequest();
9
6538
by: J.Sperlhofer | last post by:
Good morning, Javascript-Professionals. I'm looking for an possibility to show a (calculated) 64bit-Number without exponential notation. I don't want to see exponational notation within my binary numbers. To demonstrate my problem, try this code: ---- var binNumber = Math.pow(2,61);
4
4293
by: CSharpener | last post by:
This should be *so* easy! How do I convert a Byte or int to a binary string representation in C# In JavaScript, it goes like this for an int: javascript:(123).toString(2 or javascript:(0xFE).toString(2 No problem. So, how do I do the same in C#? What simple thing am I missing
4
8315
by: dirtside | last post by:
I've search far and wide for an answer, so forgive me if this is a stupid question. (Well, it probably is.) Consider the following JavaScript: var foo = new Image(); foo.src = "http://some.server.com/some_filename.gif"; Now, the browser will retrieve 'some_filename.gif' from some.server.com and put it into the object foo. What I want to do is then subsequently
9
6298
by: GiantCranesInDublin | last post by:
Hi, I am looking for the best performing solution for modifying and iterating an object graph in JavaScript. I have outlined below a simplified example of the object model and examples of how I will be using this graph. Object model:
15
9798
by: mleaver | last post by:
I want to open a second window and display a binary image that is returned from a java program via XMLRPC. The data returned is a binary encoded base64 png file. If I write the data out to a file on my server, I can display it using the following javascript: var windowHandle = window.open('about:blank','windowName','width=250,height=250'); windowHandle.document.write('<img name="myImage" src="images/test.png">');
7
2860
by: robert.differentone | last post by:
Hi, Does anybody know any javascript which converts images into binary data. Thanks in advance, R.
3
8527
by: Billy Smith | last post by:
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...
0
28058
Frinavale
by: Frinavale | last post by:
Convert a Hex number into a decimal number and a decimal number to Hex number This is a very simple script that converts decimal numbers into hex values and hex values into decimal numbers. The example following this one demonstrates how to convert decimal numbers into binary values. A hex number is a string that contains numbers between 0-9 and characters A-F; where A = 10, B = 11, ..., F = 15. (For more information please look up...
0
8619
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
9112
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
8971
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...
1
8824
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7651
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...
0
5831
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
4336
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
4571
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
1970
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.