473,805 Members | 2,076 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Compression namespace for Array

Fla
Hi!
I would like to use Compression namespace for Array, i.e. use .NET
native Compression for compress a String, or an Array of Integer whose
elements are returned values of AscW for each char of the String.
I tried with the code available @
http://msdn2.microsoft.com/en-us/lib...am(VS.80).aspx
but with no success 'cause I obtained ms.lenght buffer.length.

This is my source code for CompressData:

Private Sub CompressData()
Dim BUFFERSIZE As Integer = DataArray.Lengt h *
Marshal.SizeOf( DataArray(0))
Dim buffer(BUFFERSI ZE - 1) As Byte

'Dump integer Array DataArray in Byte Array buffer
Dim IndexValue As Integer = 0
For Index As Integer = 0 To BUFFERSIZE - 1
If ((Index << 31) = 0) Then ' if Even
buffer(Index) = (DataArray(Inde xValue) >8)
Else
buffer(Index) = (DataArray(Inde xValue) And &HFF)
IndexValue += 1
End If

Next

Dim ms As New MemoryStream()
' Use the newly created memory stream for the compressed data.
Dim compressedzipSt ream As New GZipStream(ms,
CompressionMode .Compress, True)
compressedzipSt ream.Write(buff er, 0, buffer.Length)
' Close the stream.
compressedzipSt ream.Close()
Dim BufferOut() As Byte = ms.ToArray()

End Sub

I've got the same problem also for DecompressData with the added
difficulty of using chunk of Bytes, as reported in the previous MDSN
article.

What I'm doing wrong? Is there any work-around, any trick to use
Compression not only for stream file but also for Array of Objects? Do
you have any suggestion?
Are there any commercial libraries, with no redistribuition license,
doing this?

Thanks

Nov 12 '06 #1
6 1563
Why not just encode the string so that you get an array of bytes?
Fla wrote:
Hi!
I would like to use Compression namespace for Array, i.e. use .NET
native Compression for compress a String, or an Array of Integer whose
elements are returned values of AscW for each char of the String.
I tried with the code available @
http://msdn2.microsoft.com/en-us/lib...am(VS.80).aspx
but with no success 'cause I obtained ms.lenght buffer.length.

This is my source code for CompressData:

Private Sub CompressData()
Dim BUFFERSIZE As Integer = DataArray.Lengt h *
Marshal.SizeOf( DataArray(0))
Dim buffer(BUFFERSI ZE - 1) As Byte

'Dump integer Array DataArray in Byte Array buffer
Dim IndexValue As Integer = 0
For Index As Integer = 0 To BUFFERSIZE - 1
If ((Index << 31) = 0) Then ' if Even
buffer(Index) = (DataArray(Inde xValue) >8)
Else
buffer(Index) = (DataArray(Inde xValue) And &HFF)
IndexValue += 1
End If

Next

Dim ms As New MemoryStream()
' Use the newly created memory stream for the compressed data.
Dim compressedzipSt ream As New GZipStream(ms,
CompressionMode .Compress, True)
compressedzipSt ream.Write(buff er, 0, buffer.Length)
' Close the stream.
compressedzipSt ream.Close()
Dim BufferOut() As Byte = ms.ToArray()

End Sub

I've got the same problem also for DecompressData with the added
difficulty of using chunk of Bytes, as reported in the previous MDSN
article.

What I'm doing wrong? Is there any work-around, any trick to use
Compression not only for stream file but also for Array of Objects? Do
you have any suggestion?
Are there any commercial libraries, with no redistribuition license,
doing this?

Thanks
Nov 12 '06 #2
Fla
Hi!
Did you mean System.Text.Enc oding.ASCII.Get Bytes as the following code
lines?
Dim Buffer() As Byte = System.Text.Enc oding.ASCII.Get Bytes(StringCha r)

with

For Index As Integer = 0 To 299
StringChar &= ChrW(Index + 255)
Next

Thanks

Göran Andersson ha scritto:
Why not just encode the string so that you get an array of bytes?
Fla wrote:
Hi!
[...]
Nov 12 '06 #3
Yes. Except that you would need to use a dirrerent encoding to handle
characters that is not in the ASCII character set, like UTF8.

Fla wrote:
Hi!
Did you mean System.Text.Enc oding.ASCII.Get Bytes as the following code
lines?
Dim Buffer() As Byte = System.Text.Enc oding.ASCII.Get Bytes(StringCha r)

with

For Index As Integer = 0 To 299
StringChar &= ChrW(Index + 255)
Next

Thanks

Göran Andersson ha scritto:
>Why not just encode the string so that you get an array of bytes?
Fla wrote:
>>Hi!
[...]
Nov 14 '06 #4
Fla
Göran Andersson ha scritto:
Yes. Except that you would need to use a dirrerent encoding to handle
characters that is not in the ASCII character set, like UTF8.
I can compress and decompress Array of bytes but I can't do this if I
dump the interrmediate compress byte() in a string. I'm using
encoding.unicod e.getstring to dump the intermediate compress byte() on
a string and I'm using encoding.unicod e.getbytes to get the array of
bytes to be uncompressed.
I can't get the result 'cause Deflate.Read(.. ) returns zero; I noticed
that when I try to dump the compressed byte array on a string, I get
less char as I forecast: CompressedBuffe r.length = 119 while
CompressedStrin g.Length = 57 using
Dim CompressedStrin g As String =
Encoding.Unicod e.GetString(Com pressedBuffer).
I expected CompressedStrin g.Length = CeilingUpper(11 9/2) = 60.
I'm using unicode compression in order to get a String with Char in
Unicode coding 'cause I need 2 bytes per char and storing a number 0 to
65535 in each char. Then I dump the this Unicode coded string on a
field of a db.

Any ideas? How could I dump the compressed array of bytes on an
intermediate string?
>
Fla wrote:
Hi!
Did you mean System.Text.Enc oding.ASCII.Get Bytes as the following code
lines?
Dim Buffer() As Byte = System.Text.Enc oding.ASCII.Get Bytes(StringCha r)

with

For Index As Integer = 0 To 299
StringChar &= ChrW(Index + 255)
Next

Thanks

Göran Andersson ha scritto:
Why not just encode the string so that you get an array of bytes?
Fla wrote:
Hi!
[...]
Nov 15 '06 #5
Have you checked out System.String.I ntern? I saved about 30% using this in
a
geocoder with millions of street names.

No compression required..
Nov 15 '06 #6
If you have some binary data in an array, you can't just treat it as if
it was an encoded string, because then you will lose some data when it's
decoded.

If you want a string representation of binary data, you can use the
Convert.ToBase6 4String and Convert.FromBas e64String methods to convert
to and from a base 64 string.

Fla wrote:
Göran Andersson ha scritto:
>Yes. Except that you would need to use a dirrerent encoding to handle
characters that is not in the ASCII character set, like UTF8.

I can compress and decompress Array of bytes but I can't do this if I
dump the interrmediate compress byte() in a string. I'm using
encoding.unicod e.getstring to dump the intermediate compress byte() on
a string and I'm using encoding.unicod e.getbytes to get the array of
bytes to be uncompressed.
I can't get the result 'cause Deflate.Read(.. ) returns zero; I noticed
that when I try to dump the compressed byte array on a string, I get
less char as I forecast: CompressedBuffe r.length = 119 while
CompressedStrin g.Length = 57 using
Dim CompressedStrin g As String =
Encoding.Unicod e.GetString(Com pressedBuffer).
I expected CompressedStrin g.Length = CeilingUpper(11 9/2) = 60.
I'm using unicode compression in order to get a String with Char in
Unicode coding 'cause I need 2 bytes per char and storing a number 0 to
65535 in each char. Then I dump the this Unicode coded string on a
field of a db.

Any ideas? How could I dump the compressed array of bytes on an
intermediate string?
>Fla wrote:
>>Hi!
Did you mean System.Text.Enc oding.ASCII.Get Bytes as the following code
lines?
Dim Buffer() As Byte = System.Text.Enc oding.ASCII.Get Bytes(StringCha r)

with

For Index As Integer = 0 To 299
StringChar &= ChrW(Index + 255)
Next

Thanks

Göran Andersson ha scritto:

Why not just encode the string so that you get an array of bytes?
Fla wrote:
Hi!
[...]
Nov 16 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
4617
by: m|sf|t | last post by:
All, I have a snippet of code below. In my foreach, I would like to process only 1 item per hdd value, in the case below, the echo $tib . "\n"; would only display 1 and 2, not 1,1,1,1,2,2,2,2. It doesn't matter which one shows, because I only want the unique value for hdd. $tibs = array( "tib1" => array("drive" => "C", "progress" => "on", "hdd" => "1", "partition" => "1", "compression" => "3", "backup" => "K:\\"), "tib2" =>...
4
9241
by: James N | last post by:
Here's the situation: I have 3 webforms in my project. Form 1 allows the user to select a type of report to generate. There are 2 possible type of reports, and therefore, Forms 2 and 3 are these two generated reports. When being generated, both reports will need to use the exact same data. The data are static strings and I plan to declare a global array in Form 1, so that Form 2 and 3 can share them. In other words, I don't want to be...
3
4572
by: orekinbck | last post by:
Hi There Is there any easy way to use the System.Compression tools in .NET 2.0 to compress an entire directory ? All my source code is kept in a single directory so I have written a utility that recursively backs up the directory and compresses each file as it goes. The utility has no GUI. I have attached the program here, I would be interested to get any
5
2639
by: mkarim | last post by:
I am looking for an algorithm I can use in C# that compresses small XML documents. Is there a chance of losing some literal data on decompression (as some claim)? How fast is the compression/decompression process? Thanks.
3
2616
by: Marc Gravell | last post by:
It might just be my tired eyes, but I can't see what is wrong in the following: I have a byte array filled with random data (with a fixed seed to make reproducable); I then compress and decompress this using the 2.0 GZip compression classes - however, as you see, the last byte is getting dropped. Any ideas? Almost certainly me having a blond moment ;-( Marc
4
3863
by: Angel Of Death | last post by:
If server uses HTTP 1.1 Gzip compression, how can I use the classes generated using WSDL.exe. I can do : protected override WebRequest GetWebRequest(Uri uri) { WebRequest request = base.GetWebRequest(uri); request.Headers.Add("Accept-Encoding", "gzip, deflate"); return request;
6
1084
by: Fla | last post by:
Hi! I would like to use Compression namespace for Array, i.e. use .NET native Compression for compress a String, or an Array of Integer whose elements are returned values of AscW for each char of the String. I tried with the code available @ http://msdn2.microsoft.com/en-us/library/system.io.compression.gzipstream(VS.80).aspx but with no success 'cause I obtained ms.lenght buffer.length. This is my source code for CompressData:
5
5974
by: jeremyje | last post by:
I'm writing some code that will convert a regular string to a byte for compression and then beable to convert that compressed string back into original form. Conceptually I have.... For compression string ->(Unicode Conversion) byte -(Compression + Unicode Conversion) string
3
7530
by: GiJeet | last post by:
Hello, we have an app that scans documents into TIFF format and we need to transfer them over the internet. If anyone knows of a SDK we can use that can compress TIFFs on the fly or even if it can compress them so they take up less space on the server, would be appreciated. Actually any info on handling tiff files programatically would be appreciated as I know very little about tiffs. TIA
0
9596
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10614
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10363
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10109
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7649
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6876
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5544
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4327
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3008
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.