libxml setCompressMode() only works with backslash

BlitzMax Forums/Brucey's Modules/libxml setCompressMode() only works with backslash

Difference(Posted 2009) [#1]
Hi Brucey

In Windos XP: It seems setCompressMode() only works with backslashed files, - and not when there are forward slashes in the filename:

SuperStrict
Import bah.libxml
Local doc:TxmlDoc = TxmlDoc.newDoc("1.0")

If doc Then

	Local root:TxmlNode = TxmlNode.newNode("root")
	
	doc.setRootElement(root)

	doc.setCompressMode(9)
		
	Local filename:String = "C:/data/test.dat"	
		
	'filename = filename.Replace("/","\") ' uncomment this line to get compresssion
		
	doc.saveFile(filename)

End If



Brucey(Posted 2009) [#2]
Ok. Thanks.
I suppose the module should do the conversion for you :-)


Difference(Posted 2009) [#3]
I suppose the module should do the conversion for you :-)

I think that would be the best, cause it's a subtle error, and BlitzMax tends to convert everything to forward slashes. (AppDir etc.)

Once again thanks for this extremely useful module.


Brucey(Posted 2009) [#4]
It's in SVN now.
I applied the same theory to saveFormatFile() also.

Come to think of it, I wonder if it would be possible to save direct to a TStream too. That might be useful for some people.


Difference(Posted 2009) [#5]
Great.
Come to think of it, I wonder if it would be possible to save direct to a TStream too. That might be useful for some people.

I would like to "intercept" what is read and written in order to decrypt/encrypt the compressed data to avoid tampering with saved games.

Would that be possible?


Brucey(Posted 2009) [#6]
If I can get it into a TStream, then you could probably do that, yes.

Whether or not I can... well... ;-)


Difference(Posted 2009) [#7]
lol,
No worry, I think I can do it now by using TxmlDoc.parseDoc() and TxmlDoc.ToString() zipping and encrypting myself.


Brucey(Posted 2009) [#8]
Okay, I've added TStream support to saveFile() and saveFormatFile().
This means you can now either pass in a String or a TStream.

(The function signatures have changed, but won't require a change to your code)

The only issue with TStream is you *don't* get compression, because currently Libxml itself only supports compression on files (the source is full of TODOs, so I guess they want to add that at some point).

But possibly handy to someone :-)