Stream in Stream?

BlitzMax Forums/BlitzMax Programming/Stream in Stream?

Sanctus(Posted 2011) [#1]
Hello.
I've been meaning to improve file packer and module to read faster.
Right now I read a file from a stream and store it in a bank stream.
Then I read the contentment's of the file from that bank into a resource.
That's BAD.. and slow.
I was wondering if there is anyway to create a stream out of another stream knowing the position and the length.
Sort of substream:TStream = stream.SubStream(pos,length)
Could anyone help me out with this?


Perturbatio(Posted 2011) [#2]
CopyBytes?


Local stream1:TStream = OpenFile("test.txt")'make sure it's got something to read
Local bank:TBank = createbank(1024)
Local stream2:TBankStream = TBankStream.create(bank)

stream1.seek(100)
CopyBytes(stream1, stream2, 1024)
stream2.seek(0)
print readString(stream2,1024)

print stream2.size()


Last edited 2011


Sanctus(Posted 2011) [#3]
Nope that's just as bad since the copying is there. I want the second stream to read from the same source. If it helps in any way I just need reading not writing.


Perturbatio(Posted 2011) [#4]
I'm a little confused by the request then. If you want to read from the same source, can't you just use the same stream?


_JIM(Posted 2011) [#5]
I'm guessing he wants to "separate" the "pack" stream into multiple "file" streams, thus avoiding the copying of the data into separate streams.

Not sure if it's possible.


Perturbatio(Posted 2011) [#6]
Might be possible with a TStreamWrapper?

*EDIT*
In fact, it looks like ziggy was looking to do something similar:

http://blitzbasic.com/Community/posts.php?topic=75366#842156

Last edited 2011


Sanctus(Posted 2011) [#7]
Oh yeah. That's perfect :D
Now just gotta figure a way to implement to compression and encryption in that but that's not top priority.

Thank a lot guys.