GZip Compression (Yes this old chestnut Again)

I have a client who requires this to work in .NET 4 Client Profile so no 4.5 compression improvements for me. All I need is 2 functions one to compress and one to decompress
both of which take in and return unicode strings. I have spent weeks nay months searching tweaking writing etc. to no avail, I have looked at all the existing snippets I could find but they
all either take in or return a Byte() or Stream or something else and when I tweak them to take/return a string they don't work. What I have so far (a snippet found online tweaked) is:
Public Shared Function Decompress(bytesToDecompress As String) As String
Using stream = New IO.Compression.GZipStream(New IO.MemoryStream(System.Text.Encoding.Unicode.GetBytes(bytesToDecompress)), IO.Compression.CompressionMode.Decompress)
Const size As Integer = 4096
Dim buffer = New Byte(size - 1) {}
Using memoryStream = New IO.MemoryStream()
Dim count As Integer
Do
count = stream.Read(buffer, 0, size)
If count > 0 Then
memoryStream.Write(buffer, 0, count)
End If
Loop While count > 0
Return System.Text.Encoding.Unicode.GetString(memoryStream.ToArray())
End Using
End Using
End Function
Public Shared Function Compress(Input As String) As String
Dim bytes() As Byte = System.Text.Encoding.Unicode.GetBytes(Input)
Using stream = New IO.MemoryStream()
Using zipStream = New IO.Compression.GZipStream(stream, IO.Compression.CompressionMode.Compress)
zipStream.Write(bytes, 0, bytes.Length)
Return System.Text.Encoding.Unicode.GetString(stream.ToArray())
End Using
End Using
End Function
However the problem is if you run the following you get nothing out.
Decompress(Compress("Test String"))
Please help me; I know this has been covered to death elsewhere but I am missing something when tweaking I am sure it's something very simple but it is causing me great stress! Many Many Thanks Indeed!

I have now found a workaround which may be useful to others so I am posting it here, it doesn't do exactly what was described above which would be ideal but here is the code:
Private Sub WriteCompressed(ByVal Path As String, Data As String)
Using WriteFileStream As IO.FileStream = IO.File.Create(Path)
Using DataStream As New IO.MemoryStream(System.Text.Encoding.Unicode.GetBytes(Data))
Using Compressor As IO.Compression.DeflateStream = New IO.Compression.DeflateStream(WriteFileStream, IO.Compression.CompressionMode.Compress)
DataStream.CopyTo(Compressor)
End Using
End Using
End Using
End Sub
Private Function ReadCompressed(ByVal Path As String) As String
Using ReadFileStream As IO.FileStream = System.IO.File.OpenRead(Path)
Using DataStream As New IO.MemoryStream
Using Decompressor As IO.Compression.DeflateStream = New IO.Compression.DeflateStream(ReadFileStream, IO.Compression.CompressionMode.Decompress)
Decompressor.CopyTo(DataStream)
Return System.Text.Encoding.Unicode.GetString(DataStream.ToArray)
End Using
End Using
End Using
End Function
Many thanks indeed to everyone who helped and any more input is still welcome. Thanks again!
That's great. You should propose your post as the answer to end the thread.
I just finished with a different method. However I will guess the real issue is that strings can not contain various binary values such as Nulls, Delete, Bell, Backspace, etc (as you can see zeros in RTB2 in the image below which are null
values).
I forgot to add that during testing I was receiving errors because compressed data written to a string then read from a string into bytes and decompressed would return errors during the decompressing that the data did not contain a valid GZip header. Therefore
when GZip compresses it uses some format for the compressed data that is known to Gzip. Otherwise it would not have a header in the compressed data.
You can see what binary values (Decimal) would be in a string at this link
Ascii Table.
Therefore I used the code below to get a string from a RichTextBox1 to a byte array. That is compressed and output to a byte array.
The information in the "compressed" byte array is then converted byte by byte to the bytes value in RichTextBox2 with each value separated by a comma.
To decompress the string in RichTextBox2 that text is split into a string array on a comma. Then each item is converted to a byte into a List(Of Byte). The List(Of Byte).ToArray is then decompressed back into a byte array and that byte array is converted
to a string in RichTextBox3.
I suspect the actual compressed byte array could be written to a binary file using the
BinaryWriter Class if the original strings were supposed to be compressed and attached as files for transfer somewhere.
Option Strict On
Imports System.IO
Imports System.IO.Compression
Imports System.Text
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.Location = New Point(CInt((Screen.PrimaryScreen.WorkingArea.Width / 2) - (Me.Width / 2)), CInt((Screen.PrimaryScreen.WorkingArea.Height / 2) - (Me.Height / 2)))
RichTextBox1.Text = My.Computer.FileSystem.ReadAllText("C:\Users\John\Desktop\Northwind Database.Txt")
Label1.Text = "Waiting"
Label2.Text = "Waiting"
Label3.Text = "Waiting"
Label4.Text = "Waiting"
Button2.Enabled = False
End Sub
Dim BytesCompressed() As Byte
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
RichTextBox2.Clear()
RichTextBox3.Clear()
Label1.Text = "Waiting"
Label2.Text = "Waiting"
Label3.Text = "Waiting"
Label4.Text = "Waiting"
If RichTextBox1.Text <> "" Then
Dim uniEncoding As New UnicodeEncoding()
BytesCompressed = Compress(uniEncoding.GetBytes(RichTextBox1.Text))
Label1.Text = RichTextBox1.Text.Count.ToString
Label2.Text = BytesCompressed.Count.ToString
For Each Item In BytesCompressed
RichTextBox2.AppendText(CStr(CInt(Item)) & ",")
Next
RichTextBox2.Text = RichTextBox2.Text.Remove(RichTextBox2.Text.Count - 1, 1)
End If
Button2.Enabled = True
End Sub
Private Shared Function Compress(data As Byte()) As Byte()
Using compressedStream = New MemoryStream()
Using zipStream = New GZipStream(compressedStream, CompressionMode.Compress)
zipStream.Write(data, 0, data.Length)
zipStream.Close()
Return compressedStream.ToArray()
End Using
End Using
End Function
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Button2.Enabled = False
Dim RTB2Split() As String = RichTextBox2.Text.Split(","c)
Dim BytesToUse As New List(Of Byte)
For Each Item In RTB2Split
BytesToUse.Add(CByte(Item))
Next
Label3.Text = BytesToUse.Count.ToString
Dim uniEncoding As New UnicodeEncoding()
RichTextBox3.Text = uniEncoding.GetString(Decompress(BytesToUse.ToArray))
Label4.Text = RichTextBox3.Text.Count.ToString
End Sub
Private Shared Function Decompress(data As Byte()) As Byte()
Using compressedStream = New MemoryStream(data)
Using zipStream = New GZipStream(compressedStream, CompressionMode.Decompress)
Using resultStream = New MemoryStream()
zipStream.CopyTo(resultStream)
Return resultStream.ToArray()
End Using
End Using
End Using
End Function
End Class
La vida loca

Similar Messages

  • Sudden iMac ShutDown (This old thread again)

    Is the old "iMac 27inch (2010) shuts down by itself" again, but it's getting worse since OSX 10.8. (once a week to once a day).
    Reset SMC, 12Gigs Ram (2x Apple chips), reinstalled OS, one USB port with Hub with Canon scanner, external time machine (1TB), cable for iPhone/iPad, headset, one USB port for wireless mouse.
    GPU/CPU running hot around 150+ degrees, so installed smcFanControl, now at 99 to 115.
    Any suggestions?. The Hub?, the Apple Ram chips?, more Ram?, less Ram?. Run some diagnostics?, Software apps?. Help?.

    >Has the iMac stayed running since installing SMC Fan control?
    Yes.
    >What have you set the iMac's fans rpm to?
    ODD: 2417 RPM
    HDD: 3219 RPM
    CPU: 1522 RPM
    >To test your iMac, unplug all peripherals except the keyboard and mouse.
    See if your iMac stays running.
    No, good call. It died with all USB devives unplugged (keyboard/mouse wireless).

  • I have a number of gzip compressed archive files I'd like to delete. How do I do this?

    I have a number of gzip compressed
    archive files I'd like to delete. How do I do this

    Select files and use one of the following:
    Drag to Trash.
    CTRL- or RIGHT-click and select Move To Trash from the context menu.
    Select Move To Trash from the Finder's File menu.
    Press the COMMAND and Delete keys.
    Then Empty the Trash using one of the following:
    CTRL- or RIGHT-click on the Trashcan and select Empty from the context menu.
    Select Empty the Trash from the Finder's Finder menu.
    Press SHIFT-COMMAND-Delete keys.

  • How Do I enable gzip compression on Sun One Web Server 6.0

    How Do I enable gzip compression on Sun One Web Server 6.0

    Hi,
    Sun ONE webserver 6.0 is over 5 years old and is reaching end of support life. Please consider upgrading to webserver 6.1sp5 which is free:
    http://www.sun.com/download/products.xml?id=434aec1d
    or else the preview version of WebServer 7.0 (also free)):
    http://www.sun.com/download/products.xml?id=446518d5
    For webserver 6.1, the docs for setting up compression are at:
    http://docs.sun.com/source/819-0130/agcontnt.html#wp1019634
    and
    http://docs.sun.com/source/817-6252/npgnsapi.html
    Hope this helps

  • GZIP Compression Issue in Weblogic 8.1

    Has anyone experienced issues with gzip compression filtering in 8.1?
    After about 2 months of dev. and testing with the filter, a bug has been found
    in our portal, and I have traced it back to the filter that I downloaded from
    dev2dev code and utilities.
    It is strange. The only time I see an issue is when a user clicks the "back button"
    in the browser itself to go back to a previous page, AND then clicks a link (for
    example) in a portlet that is tied to an action in a jpf for that portlet. The
    error only happens for actions in a portlet that are local to that portlet (no
    forwarding to other portlets or anything fancy)...just pure "local internal forwards."
    If you do this, USING THE BACK BUTTON to get back to this page with the portlet,
    when you click the action, you are actually taken to the page where you were when
    you clicked the back button.
    I have re-created this is simple portals that have no content, so I know it is
    not something else I introduced.
    Any ideas? Maybe it is the filter-mapping pattern I am using??? I am currently
    mapping on *.portal, but this is the only situation that seems to break.

    For those interested, I have some updates on this subject and someone out there sent me a mail asking if I ever found anything out.
    Basically, when I encountered this issue the first time, I was working on a SP2 Portal. We were having numerous small bugs like this one with SP2 that centered around the back button or refresh button. BEA gave us a "super patch" back in July or so that when applied to our SP2 project, fixed our issue. I have sense moved onto SP3, and I did not see the compression issue (so I think SP3 must have the patches correctly setup...like I would assume it would).

  • After updating to Firefox 5 my Realplayer Recorder is not working due to that add on not being compatible. How do I get this to work again?

    After updating to Firefox 5 my Realplayer Recorder is not working due to that add on not being compatible. How do I get this to work again?

    Blue
    It sounds like you restored from an old back-up.  Did you back-up just before your software update?  It will use your last one and if your last back-up was a ywear old then it will use that one.
    In general, if you are getting these messages on your iPhones select logout (when you get that Apple Id request) and then log back in with your newer ID.
    Sorry for your losses.
    Cheers

  • Airplay from ipad 1 gen to ATV 3 gen "an error occurred loading this content try again later"

    Hi everyone!,
    I just bought a new Apple tv 3 gen which is great.
    My situation is the next. I have an add hoc wifi which obviously cant connect with my ATV cause ATV doesnt have browser to set user password. This connection is not quite fast, so problem added to the previous. The thing is that I want to use my ipad 1 gen to airplay content to the apple tv. It works great with pictures and even music (my own library or spotify streamed music).
    The problem comes when I try to airplay video from youtube or embedded video from safari so it keeps saying "an error occurred loading this content try again later".
    I tried with my iphone 6 and with an iphone 5 and the same, no video from youtube nor web.
    If I try to airplay a video that is inside my phone, it works flawlessly.
    the specs say that you need at least 6mb connection, but that seems to stream directly from the ATV cause ATV doesn't have hd to store data, but my ipad streams it and plays it like a charm, but when I airplay to the apple tv got the problem.
    I also can stream video from my old mac mini through the network using airparrot but it doesn't allow me to send audio, seems to be problems sending audio and video while streaming..
    Any help?
    does anyone solved it?
    thanks in an advance!

    Two problems seems to be causing this:
    1- My poor download connection. Testing its speed barely reaches 1.5 download speed, though it's enough to stream movies with ipad, or computers.
    2- the router I have connected to my antenna to create my own network. it is a normal 150 mbps tp-link range extender which is used to create a wifi. This 150 mbps might be much more than a half.
    I have tried with a 300 mbps router and now I don´t get the error, but it seems that streaming with my ipad and airplay to the apple tv overloads the network and it loads quite slow in my atv.

  • HT2736 I gifted an application and the user has not redeemed code...lost her email can I send this to her again?

    I gifted an application and the user has not redeemed code...lost her email can I send this to her again?

    Yes, you can resend. See:
    http://support.apple.com/kb/HT1541
    Regards.

  • Enabling GZIP compression on the HTTPBC or a suggested alternative approach

    Hi,
    I posted this on the openusb-users group, but I haven't come up with a good solution yet.
    Any takers?
    Thanks,
    Rob
    http://openesb-users.794670.n2.nabble.com/gzip-compression-support-in-HTTP-BC-tp5366301.html
    Does anybody know whether the HTTP BC shares all of the same features that the Glassfish HTTP listener supports such as gzip compression? If so, where are those parameters specified for the HTTP BC? (Compression of the XML can of course make a tremendous bandwidth savings for the typical XML passed around via SOAP.)
    Please see:
    http://docs.sun.com/app/docs/doc/820-4338/abhco?a=view
    compression - on
    Specifies use of HTTP/1.1 GZIP compression to save server bandwidth. Allowed values are:
    off – Disables compression.
    on – Compresses data.
    force – Forces data compression in all cases.
    positive integer – Specifies the minimum amount of data required before the output is compressed.
    If the content-length is not known, the output is compressed only if compression is set to on or force.
    compressableMimeType text/html,text/xml,text/plain
    Specifies a comma-separated list of MIME types for which HTTP compression is used.
    If there isn't a way to configure the HTTPBC, What would be the best way to enable a gzip compression of the XML for the HTTPBC or JBI framework in general?
    My first approach might be to just have a Glassfish HTTP-Listener based WebService delegate to the HTTPBC or more directly to the JBI SE components if possible. Maybe a filter on the HTTPBC to gzip the payload? Are there any plans to refactor HTTPBC to use the Glassfish HTTP Listener code, it appears to have more capability and options?
    Rob

    I tried it did not work.
    Below are the steps which I did:
    Test2: Table level compression test
    ===================================
    CREATE TABLE SCOTT.TEST_PMT_TAB_COMP
    PMT_ID INTEGER NOT NULL,
    PMT_AGCY_NBR CHAR(7 BYTE),
    PMT_SBAGCY_NBR CHAR(7 BYTE),
    PMT_PAY_DT DATE,
    PMT_POL_NBR CHAR(14 BYTE),
    PMT_POL_SEQ_NBR CHAR(2 BYTE),
    PMT_PRM_INSD_NM VARCHAR2(30 BYTE),
    PMT_PAY_TYP_DESC VARCHAR2(20 BYTE),
    PMT_PAY_AMT NUMBER(11,2),
    PMT_POST_DT DATE
    COMPRESS FOR ALL OPERATIONS;
    inserting record from the test table:
    SQL> insert into SCOTT.TEST_PMT_TAB_COMP select * from SCOTT.TEST_PMT;
    5051013 rows created.
    SQL> commit;
    Commit complete.
    SQL> select count(*) from scott.TEST_PMT_TAB_COMP;
    COUNT(*)
    5051013
    Checking size:
    SQL> select bytes/1024/1024, segment_name, owner, segment_type, tablespace_name from dba_segments where segment_name='TEST_PMT_TAB_COMP';
    BYTES/1024/1024 SEGMENT_NAME OWNER SEGMENT_TYPE TABLESPACE_NAME
    776 TEST_PMT_TAB_COMP SCOTT TABLE USERS_DATA01
    SQL> select owner, table_name, COMPRESSION, COMPRESS_FOR from dba_tables where table_name='TEST_PMT_TAB_COMP';
    OWNER TABLE_NAME COMPRESS COMPRESS_FOR
    SCOTT TEST_PMT_TAB_COMP ENABLED OLTP
    Now it is occupying more size.

  • Using native IIS 6.0 Gzip Compression in front of WLS 8.1 SP5

    (IIS 6.0 => ISAPI proxy(/*) => WLS 8.1 SP5 )
    Instead of usign a servlet filter and Gzip compression inside the, I would like to test the IIS 6.0 Gzip compression. I want to do this because the IIS server farm is severley underutilized in CPU and seems like the best use of that resource.
    It is easy to config this in IIS 6.0. However, I can get IIS served static pages back compressed, but requests proxied to WLS return uncompressed, even though I have configured DLL calls to be zipped inide IIS.
    The question is: has anyone done this and if so, what is the config.

    I am trying to solve the same issue. This is what I've discovered so far. I have been able to get page compression to work with IIS 4.0 and 5.0 using the iisproxy plugin. The trick was to add both "jsp" and "wlforward" extensions to the script file list to compress dynamic files.
    IIS 6.0 changed the compression module from an ISAPI plugin to internal code. The configurations look the same, but I am not able to get JSPs to be compressed. I can compress static files, I can compress ASP files so I know I have compression working and I know that I have dynamic file compression working.
    This is a great article on configuring compression in IIS, it should get you started in the right direction. I know it's from a .Net site, but the fundamentals are the same and it's very well written.
    http://dotnetjunkies.com/Article/16267D49-4C6E-4063-AB12-853761D31E66.dcik
    I am now trying to figure out how to get IIS 6.0 dynamic page compression to work with the iisproxy plugin. Any ideas?

  • I recently updraded the oporating system on my 4S phone and now I can't get my email.  I've rebooted several times to no avail. What should I do to get this thing working again?

    I recently upgraded my phone software to iOS 6 and now my email will not download.  I have tried to reboot the phone to no avail.  Anyone have any suggestions as to how I can get this phone working again?

    You can't merge the backups, you'll have to delete the backup of your old phone.  If it says it's currently in use when you try, that will normally clear up on its own but may take 3-5 days to do so.  Give it a few days and try deleting the old backup again.
    In the meantime, you can create a manual backup of your new phone on your computer by connecting it to your computer, opening iTunes, clicking on the name of your phone in iTuens, going to the Summary tab of your iTunes sync settings and clicking Back Up Now.  Also go to File>Devices>Transfer Purchases.  Then you'll be safe until you can start backup up to iCloud again.

  • Fcp wont let me export to the compresser 4 all of a sudden it taking me too compresser 3 this just started happen what do i do

    let me export to the compresser 4 all of a sudden it taking me too compresser 3 this just started happen what do i do

    I don't know why this just started to happen unless v3.0 were somehow moved from its location.
    I once had FCP7 get confused between Motion 4 and Motion 5 when I failed to follow Apple's installation recommendations but never a problem with FCPX going to the wrong app. (But I don't use the Send to Compressor workflow.)
    When you have the legacy apps already installed on your system, the new pro app download moves the old ones into a folder, named Final Cut Studio. That's what I was getting at when I suggested you create a new folder for C3.
    Russ

  • I have an iMac g5 it's about 9 years old, I want to buy adobe photoshop what version should I buy that will run well on a computer this old?

    I have a 9 year old  iMac g5 and I'm about to start a photography course therefore would like to purchase and install photoshop.
    I want to know if this iMac will load and run this software well, and if so what version should I buy for this old computer!
    thank you

    WZZZ wrote:
    The  wording is confusing. I just tried one of the DLs and it is working. Whether it will actually install now, I have no idea. If the activation servers have been disabled (because of a technical issue), probably not. Whether this is only temporary, I have no idea. I would think Adobe would just withdraw the entire page if they wanted. From the time this first appeared a few weeks ago until now I know it was working and could be installed using the provided serial #s. There was nothing about needing to actually have purchased it originally.
    Ginger:
    I downloaded CS2 from the Adobe site BEFORE this recent notice was posted and it is the only version that I have and use.
    The new notice is VERY confusing, because if you were a prior purchaser of it originally, why would you need their newly supplied serial number (which is what I use since I was NOT a prior purchaser. But again, when I downloaded and installed CS2 there was no such notice).
    I suggest that you see if it downloads, installs and works with that serial number, as free is always better than not!   (especially since it is known that iMac G5's are prone to hardware failure from bad capacitors! I had many of them...)
                                  [click on image to enlarge]
    WZZZ wrote:
    I don't know how strict the OS requirements are. I do know that my old G5 iMac, even upgraded to Leopard, was able to run CS2. In fact, using Rosetta, CS2 still runs on my Snow Leopard.
    As you can see from the image, CS2 is running in my Snow Leopard (with Rosetta) environment in Parallels concurrently with Lion.

  • GZip Compression filter for Weblogic 11g.

    Hi,
    I are using WLS 11g for our application development. I have identified and used PlanetJ gzip compression filter and its working fine in our dev environment. I am looking for alternate commercial supported gzip filter for wls.
    Can anybody suggest a commercial gzip filter? Or PlanetJ gzip filter is a good one?. We excepect the application to scale up to 150 users and the filter selected should not be an issue for this. Also is there any official oracle/wls supported gzip filters available?
    Any help on this is highly appreciated.
    regards
    jossy.

    Thank you for the answer. But currently we are looking to including filter at WLS as the suggestion by you will involve lot of architectural changes. Could you please answer if any weblogic/oracle supported filter is avaialble for enabling compression at WLS.
    thanks and regards
    jossy.

  • An OLD INACTIVE email address, asking for a password, continues to show up to play certain selections in my iTunes Music Library.  I want to REMOVE this old email, HOW DO I REMOVE IT!!  All attempts to remove it have failed!

    An OLD INACTIVE email address, asking for a password, continues to show up to play certain selections in my iTunes Music Library.  I want to REMOVE this old email address, HOW DO I REMOVE IT!!  All attempts to remove it have failed!

    Yes, if you change your Apple ID to your new email address. You don't have to. Under those sort of situations you can speak to Apple about transferring your purchased items to the new Apple ID, and see if they will help you.
    You don't lose access to your older purchased items, you simply cannot update or re-download them or, in some cases, use them without providing the old Apple ID and password. All purchased items are permanently tied to the Apple ID used at time of purchase.

Maybe you are looking for

  • Iphone 4s kicks me out of itunes

    I just bought an iPhone 4s yesterday. It came with iOS7 on it already. Today, it started randomly kicking me off my iTunes app. iTunes works on my PC. And the App store on my phone works fine too. This is the only app it kicks me off of. The phone ca

  • Creating a set of characters

    This seems simple, but it is really bothering me because it is not working. How do I make a simple set of characters. For example: I would like to make a set called "operators" and i would like it to include '-', '+', '*', '%', etc. I will also have

  • How to put photos from usb to computer

    how to import photos from usb to laptop

  • COI Equity method...

    Have scenario where A is has invested in 45% in B. It is consolidated under equity method. But both are group companies in the SAP instance and both company financial data is brought to BCS cube… when I read the equity statement rule … following is m

  • Is it possible to install oracle downlaoded from otn and update license key

    Hi Experts, I have to install oracle 10gR2 10.2.0.1. Customer will provide me the licsense keys but they could not arrange me media/dvd. Is it ok to download 10gR2 from url http://www.oracle.com/technetwork/database/10201winsoft-095341.html and updat