|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
GZipStream Decompress always reads 4K minimum...!I have a network stream of data I am reading, of which, a section is
compressed and can be decompressed using GZipStream's decompression. This part works great, however, even if the part being decompressed is 1K, GZipStream /always/ reads 4K minimum off my primary stream. Using .NET Reflector I can see they have a 4K buffer internally and always read in chunks of 4K. Basically, I have to force GZipStream to only read what is compressed, and no more. This should be possible because I am reading fixed sized structures out of GZipStream and upon the last structure I should begin reading uncompressed data again. Do I have any options here? Thanks
Show quote
"Bob" <nob***@nowhere.com> wrote in message Sure. Just read off your compressed data into a fixed-size buffer and feed news:%23SrM7FGKGHA.1320@TK2MSFTNGP15.phx.gbl... >I have a network stream of data I am reading, of which, a section is >compressed and can be decompressed using GZipStream's decompression. This >part works great, however, even if the part being decompressed is 1K, >GZipStream /always/ reads 4K minimum off my primary stream. Using .NET >Reflector I can see they have a 4K buffer internally and always read in >chunks of 4K. > > Basically, I have to force GZipStream to only read what is compressed, and > no more. This should be possible because I am reading fixed sized > structures out of GZipStream and upon the last structure I should begin > reading uncompressed data again. > > Do I have any options here? that to the GZipStream by wrapping it in a MemoryStream. byte[] buf = new byte[1024]; //read fixed-length compressed data into buf GZipStream gs = new GZipStream(new MemoryStream(buf)); David Thanks for responding... but thats the problem, I don't know the exact size
of the compressed data. I just know "when to stop reading compressed data." Even if I add an additional stream between the network stream and GZipStream, I don't know where to position the uncompressed data (I don't know how much compressed data GZipStream read, I only know how much uncompressed data was read). Show quote "David Browne" <davidbaxterbrowne no potted m***@hotmail.com> wrote in message news:%23f1Z2OGKGHA.2828@TK2MSFTNGP12.phx.gbl... > > "Bob" <nob***@nowhere.com> wrote in message > news:%23SrM7FGKGHA.1320@TK2MSFTNGP15.phx.gbl... >>I have a network stream of data I am reading, of which, a section is >>compressed and can be decompressed using GZipStream's decompression. This >>part works great, however, even if the part being decompressed is 1K, >>GZipStream /always/ reads 4K minimum off my primary stream. Using .NET >>Reflector I can see they have a 4K buffer internally and always read in >>chunks of 4K. >> >> Basically, I have to force GZipStream to only read what is compressed, >> and no more. This should be possible because I am reading fixed sized >> structures out of GZipStream and upon the last structure I should begin >> reading uncompressed data again. >> >> Do I have any options here? > > > Sure. Just read off your compressed data into a fixed-size buffer and > feed that to the GZipStream by wrapping it in a MemoryStream. > > byte[] buf = new byte[1024]; > //read fixed-length compressed data into buf > GZipStream gs = new GZipStream(new MemoryStream(buf)); > > David > You could also write the size of the compressed data first.
-- Show quoteRegards, Lloyd Dupont NovaMind development team NovaMind Software Mind Mapping Software <www.nova-mind.com> "Bob" <nob***@nowhere.com> wrote in message news:ew3I4VGKGHA.1532@TK2MSFTNGP12.phx.gbl... > Thanks for responding... but thats the problem, I don't know the exact > size of the compressed data. I just know "when to stop reading compressed > data." Even if I add an additional stream between the network stream and > GZipStream, I don't know where to position the uncompressed data (I don't > know how much compressed data GZipStream read, I only know how much > uncompressed data was read). > > > "David Browne" <davidbaxterbrowne no potted m***@hotmail.com> wrote in > message news:%23f1Z2OGKGHA.2828@TK2MSFTNGP12.phx.gbl... >> >> "Bob" <nob***@nowhere.com> wrote in message >> news:%23SrM7FGKGHA.1320@TK2MSFTNGP15.phx.gbl... >>>I have a network stream of data I am reading, of which, a section is >>>compressed and can be decompressed using GZipStream's decompression. >>>This part works great, however, even if the part being decompressed is >>>1K, GZipStream /always/ reads 4K minimum off my primary stream. Using >>>.NET Reflector I can see they have a 4K buffer internally and always read >>>in chunks of 4K. >>> >>> Basically, I have to force GZipStream to only read what is compressed, >>> and no more. This should be possible because I am reading fixed sized >>> structures out of GZipStream and upon the last structure I should begin >>> reading uncompressed data again. >>> >>> Do I have any options here? >> >> >> Sure. Just read off your compressed data into a fixed-size buffer and >> feed that to the GZipStream by wrapping it in a MemoryStream. >> >> byte[] buf = new byte[1024]; >> //read fixed-length compressed data into buf >> GZipStream gs = new GZipStream(new MemoryStream(buf)); >> >> David >> > > Bob <nob***@nowhere.com> wrote:
> Thanks for responding... but thats the problem, I don't know the exact size So you've got some amount of compressed data and then some other data, > of the compressed data. I just know "when to stop reading compressed data." > Even if I add an additional stream between the network stream and > GZipStream, I don't know where to position the uncompressed data (I don't > know how much compressed data GZipStream read, I only know how much > uncompressed data was read). with no idea beforehand how much compressed data there was? That's a really bad protocol design, unfortunately - you're likely to have difficulty in decoding it. Do you control the protocol, or does it "belong" to someone else? -- Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet If replying to the group, please do not mail me too You might try:
http://www.icsharpcode.net/OpenSource/SharpZipLib/Default.aspx -- Show quoteRegards, Lloyd Dupont NovaMind development team NovaMind Software Mind Mapping Software <www.nova-mind.com> "Bob" <nob***@nowhere.com> wrote in message news:%23SrM7FGKGHA.1320@TK2MSFTNGP15.phx.gbl... >I have a network stream of data I am reading, of which, a section is >compressed and can be decompressed using GZipStream's decompression. This >part works great, however, even if the part being decompressed is 1K, >GZipStream /always/ reads 4K minimum off my primary stream. Using .NET >Reflector I can see they have a 4K buffer internally and always read in >chunks of 4K. > > Basically, I have to force GZipStream to only read what is compressed, and > no more. This should be possible because I am reading fixed sized > structures out of GZipStream and upon the last structure I should begin > reading uncompressed data again. > > Do I have any options here? > > Thanks > |
|||||||||||||||||||||||