PC Review
Forums
Newsgroups
Microsoft DotNet
Microsoft Dot NET Compact Framework
Zipping and unzipping
Forums
Newsgroups
Microsoft DotNet
Microsoft Dot NET Compact Framework
Zipping and unzipping
![]() |
Zipping and unzipping |
|
|
Thread Tools | Rate Thread |
|
|
#1 |
|
Guest
Posts: n/a
|
Hi all,
I don't know whether is the best place for posting my message, but it just drives me crazy and didn't find a better newgroup for this. I'm using the ICSharpCode.SharpZipLib for zipping a string to a compressed string and the other way around. But when I do a compress/uncompress on "Wim Lambrechts" I received "Wae Daebrec`ts", so it seems a single bit in each byte is turned off. I'm using the following code for compressing a string into a compressed string public static string CompressString (string input) { MemoryStream instream = new MemoryStream(Encoding.ASCII.GetBytes(input)); byte[] buffer = new byte[instream.Length]; instream.Read(buffer, 0, buffer.Length); instream.Close(); MemoryStream outstream = new MemoryStream(); ZipOutputStream s = new ZipOutputStream(outstream); s.SetLength(9); ZipEntry entry = new ZipEntry(""); Crc32 crc = new Crc32(); crc.Reset(); crc.Update(buffer); entry.Size = buffer.Length; entry.Crc = crc.Value; s.PutNextEntry(entry); s.Write(buffer, 0, buffer.Length); s.Finish(); s.Close(); return (new ASCIIEncoding().GetString(outstream.GetBuffer())); } and for uncompressing: public static string DecompressString2 (string input) { MemoryStream instream = new MemoryStream(Encoding.ASCII.GetBytes(input)); MemoryStream outstream = new MemoryStream(); ZipInputStream s = new ZipInputStream(instream); s.GetNextEntry(); int size = 2048; byte[] data = new byte[2048]; while (true) { size = s.Read(data, 0, data.Length); if (size > 0) { outstream.Write(data, 0, size); } else { break; } } return (new ASCIIEncoding().GetString(outstream.GetBuffer())); } Again, it drives me crazy: any help is welcome !!! Wim |
|
|
|
#2 |
|
Guest
Posts: n/a
|
Since all Windows CE strings are Unicode system-wide, you should use Unicode
encoding rather than ASCII as you have used in the code below. Peter -- Peter Foot Windows Embedded MVP OpenNETCF.org Senior Advisor www.inthehand.com | www.opennetcf.org "wl" <no-spam@no-spam.no-spam> wrote in message news:%23IpPolWqDHA.2404@TK2MSFTNGP12.phx.gbl... > Hi all, > > I don't know whether is the best place for posting my message, but it just > drives me crazy and didn't find a better newgroup for this. > I'm using the ICSharpCode.SharpZipLib for zipping a string to a compressed > string and the other way around. > > But when I do a compress/uncompress on "Wim Lambrechts" I received "Wae > Daebrec`ts", so it seems a single bit in each byte is turned off. > > I'm using the following code for compressing a string into a compressed > string > > > public static string CompressString (string input) > > { > > MemoryStream instream = new MemoryStream(Encoding.ASCII.GetBytes(input)); > > byte[] buffer = new byte[instream.Length]; > > instream.Read(buffer, 0, buffer.Length); > > instream.Close(); > > MemoryStream outstream = new MemoryStream(); > > ZipOutputStream s = new ZipOutputStream(outstream); > > s.SetLength(9); > > > ZipEntry entry = new ZipEntry(""); > > Crc32 crc = new Crc32(); > > crc.Reset(); > > crc.Update(buffer); > > entry.Size = buffer.Length; > > entry.Crc = crc.Value; > > > s.PutNextEntry(entry); > > s.Write(buffer, 0, buffer.Length); > > s.Finish(); > > s.Close(); > > return (new ASCIIEncoding().GetString(outstream.GetBuffer())); > > } > > > > and for uncompressing: > > > > public static string DecompressString2 (string input) > > { > > MemoryStream instream = new MemoryStream(Encoding.ASCII.GetBytes(input)); > > MemoryStream outstream = new MemoryStream(); > > ZipInputStream s = new ZipInputStream(instream); > > s.GetNextEntry(); > > int size = 2048; > > byte[] data = new byte[2048]; > > while (true) > > { > > size = s.Read(data, 0, data.Length); > > if (size > 0) > > { > > outstream.Write(data, 0, size); > > } > > else > > { > > break; > > } > > } > > return (new ASCIIEncoding().GetString(outstream.GetBuffer())); > > } > > > Again, it drives me crazy: any help is welcome !!! > > Wim > > |
|
|
|
#3 |
|
Guest
Posts: n/a
|
Peter,
Thanks for the info: I must admit I didn't try it yet in a compact framework application (is the intention though). I did change the encoding and now it works !!! Didn't know what it has to do with the encoding though ? Thanks again !!! Wim "Peter Foot [MVP]" <feedback@nospam-inthehand.com> wrote in message news:OWvaHqWqDHA.3320@tk2msftngp13.phx.gbl... > Since all Windows CE strings are Unicode system-wide, you should use Unicode > encoding rather than ASCII as you have used in the code below. > > Peter > > -- > Peter Foot > Windows Embedded MVP > OpenNETCF.org Senior Advisor > www.inthehand.com | www.opennetcf.org > > "wl" <no-spam@no-spam.no-spam> wrote in message > news:%23IpPolWqDHA.2404@TK2MSFTNGP12.phx.gbl... > > Hi all, > > > > I don't know whether is the best place for posting my message, but it just > > drives me crazy and didn't find a better newgroup for this. > > I'm using the ICSharpCode.SharpZipLib for zipping a string to a compressed > > string and the other way around. > > > > But when I do a compress/uncompress on "Wim Lambrechts" I received "Wae > > Daebrec`ts", so it seems a single bit in each byte is turned off. > > > > I'm using the following code for compressing a string into a compressed > > string > > > > > > public static string CompressString (string input) > > > > { > > > > MemoryStream instream = new MemoryStream(Encoding.ASCII.GetBytes(input)); > > > > byte[] buffer = new byte[instream.Length]; > > > > instream.Read(buffer, 0, buffer.Length); > > > > instream.Close(); > > > > MemoryStream outstream = new MemoryStream(); > > > > ZipOutputStream s = new ZipOutputStream(outstream); > > > > s.SetLength(9); > > > > > > ZipEntry entry = new ZipEntry(""); > > > > Crc32 crc = new Crc32(); > > > > crc.Reset(); > > > > crc.Update(buffer); > > > > entry.Size = buffer.Length; > > > > entry.Crc = crc.Value; > > > > > > s.PutNextEntry(entry); > > > > s.Write(buffer, 0, buffer.Length); > > > > s.Finish(); > > > > s.Close(); > > > > return (new ASCIIEncoding().GetString(outstream.GetBuffer())); > > > > } > > > > > > > > and for uncompressing: > > > > > > > > public static string DecompressString2 (string input) > > > > { > > > > MemoryStream instream = new MemoryStream(Encoding.ASCII.GetBytes(input)); > > > > MemoryStream outstream = new MemoryStream(); > > > > ZipInputStream s = new ZipInputStream(instream); > > > > s.GetNextEntry(); > > > > int size = 2048; > > > > byte[] data = new byte[2048]; > > > > while (true) > > > > { > > > > size = s.Read(data, 0, data.Length); > > > > if (size > 0) > > > > { > > > > outstream.Write(data, 0, size); > > > > } > > > > else > > > > { > > > > break; > > > > } > > > > } > > > > return (new ASCIIEncoding().GetString(outstream.GetBuffer())); > > > > } > > > > > > Again, it drives me crazy: any help is welcome !!! > > > > Wim > > > > > > |
|
![]() |
|
| Thread Tools | |
| Rate This Thread | |
|
|

Main Page 

