Simple Way To Compare Streams
Is there a simple way to compare Stream data between two objects?
We have used $ZCRC to create a checksum and that seems to be work.
We have also read each line of the streams and compared them and that seems to work too.
We just think there has to be a simpler way than looping through all the lines of the stream.
Any suggestions would be appreciated.
Comments
Well, not sure if this would work but maybe you can set the stream into a dynamic object using the stream>base64 transformation and compare base64 Vs base64.
https://docs.intersystems.com/iris20242/csp/documatic/%25CSP.Documatic…
Luis, Thanks, How does one go about loading a persistent object's stream data into a dynamic object?
It's really easy, to declare a dynamic object you just need:
set dynamicObject = {}
do dynamicObject.%Set(...)https://docs.intersystems.com/csp/docbook/Doc.View.cls?FIND=CLASSES+%25…
I miss how you are going to compare the two base64 json properties.
If you assume that the stream AND the base64 converted stream sizes are less than maximum string length, then I miss the point of converting to base64.
very quick and dirty test, probably only works on small streams, also needs to actually read the whole stream for compare.
# test compare - streams are same
set stream1=##class(%Stream.TmpCharacter).%New()
set stream2=##class(%Stream.TmpCharacter).%New()
do stream1.WriteLine("ABC123")
do stream2.WriteLine("ABC123")
do stream1.Rewind()
do stream2.Rewind()
w (stream1.Read() = stream2.Read())
1
# test compare - stream are different
set stream1=##class(%Stream.TmpCharacter).%New()
set stream2=##class(%Stream.TmpCharacter).%New()
do stream1.WriteLine("ABC123")
do stream2.WriteLine("DEF456")
do stream1.Rewind()
do stream2.Rewind()
w (stream1.Read() = stream2.Read())
0This works only if you assume that the stream size is less than the maximum string length.
It seems to me that in this case it would be advisable to use a comparison of stream hashes, using, for example, the SHA3HashStream method.