Comparing jpgs via reponseStreams?

T

ty

Hello,

I have responseStreams of jpg data from different URLs. How can I find
out if they are the same images? Different URLs can contain the same
image data.

Is it possible to compare random bytes from each stream if the Content-
Lengths are the same? If so, how does reading from the stream work is
JS?

Thanks!
Ty
 
T

Thomas 'PointedEars' Lahn

ty said:
I have responseStreams of jpg data from different URLs.

What is a "responseStream"?
How can I find out if they are the same images?
Different URLs can contain the same image data.

Compare sizes, compare checksums, compare byte by byte (as fdupes(1) does).
In that order.
Is it possible to compare random bytes from each stream if the Content-
Lengths are the same?

Yes, but not useful.
If so, how does reading from the stream work [in] JS?

As with any string. But ISTM you are asking the wrong question.
Why would you need to compare "responseStreams" in the first place?


PointedEars
 
T

ty

What is a "responseStream"?

Binary stream returned from a XMLHTTP response.
Compare sizes, compare checksums, compare byte by byte (as fdupes(1) does).
 In that order.

Yes, exactly. Wondering how this works from Javascript. I can't
fallback on VBScript, btw.
If so, how does reading from the stream work [in] JS?

As with any string.  But ISTM you are asking the wrong question.
Why would you need to compare "responseStreams" in the first place?

I just need to fetch two images via AJAX and figure out if they are
exactly the same.
 
B

Bart Van der Donck

T

ty

Hear, hear...

This code is within a Google gadget. Using the server doesn't make
sense in this case. Just want to see what's possible.
 
T

Thomas 'PointedEars' Lahn

Bart said:
Thomas said:
ty said:
If so, how does reading from the stream work [in] JS?
As with any string.

Objection, Your Honour ! You can't trust how browsers handle raw binary
data in javascript variables.

Can't I?
I would go for a Base64-encoding at the server; perhaps a bit
uneffecient, but it does guarantee the correct bytes.

I think that's *unnecessarily* inefficient.


PointedEars
 
T

Thomas 'PointedEars' Lahn

ty said:
Binary stream returned from a XMLHTTP response.
OK.


Yes, exactly. Wondering how this works from Javascript. I can't
fallback on VBScript, btw.

You have two strings of characters and compare them against each other.
The programming language hardly matters, does it?
If so, how does reading from the stream work [in] JS?
As with any string. But ISTM you are asking the wrong question.
Why would you need to compare "responseStreams" in the first place?

I just need to fetch two images via AJAX and figure out if they are
exactly the same.

Why?


PointedEars
 
T

ty

Comparing the streams does not work out-of-the-box. This is why I ask.
Was wondering if there were stream/byte reading methods available. The
responseStream allow much.
 
T

Thomas 'PointedEars' Lahn

ty said:
Comparing the streams does not work out-of-the-box.

Yes, it does. The `==' and `===' operators are readily available.
This is why I ask.

But you have not answered my question: Why do you think a comparison would
be necessary in the first place?
Was wondering if there were stream/byte reading methods available.

There are string methods available, and since your stream would be a string ...
The responseStream allow much.

That's a useless statement.

You would be well-advised to quote properly (as you had already been asked
before) if you asked for further advice.


PointedEars
 
B

Bart Van der Donck

Thomas said:

Some quick examples using the following page:
http://www.ajax-cross-domain.com/runit/binary.htm

- The document.write output looks totally different in MSIE 7.0.6,
Firefox 3.0.5 and Opera 9.22.

- alert(ACD.responseText.charCodeAt(466));
MSIE 7.0.6 : 125
Firefox 3.0.5 : 91
Opera 9.22 : 199

- alert(ACD.responseText.length);
MSIE 7.0.6 : 1289
Firefox 3.0.5 : 1330
Opera 9.22 : 1394

- alert(ACD.responseText.indexOf('G'));
MSIE 7.0.6 : 27
Firefox 3.0.5 : 34
Opera 9.22 : 34

- Regex doesn't work:
ACD.responseText = ACD.responseText.replace(/.$/,'');
alert(ACD.responseText.length);
MSIE 7.0.6 : 1289
Firefox 3.0.5 : 1330
Opera 9.22 : 1394

etc.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,071
Latest member
MetabolicSolutionsKeto

Latest Threads

Top