gzip base64 encode and decode string on both linux and windows
Asked Answered
M

2

19

I have a encoded string which was encoded using below command on linux machine,

cat <file-name> | gzip | base64 -w0

And I am able to decode and string using below method,

echo '<encoded-string> | base64 -di | zcat

Is there any way to decode the same string on windows machine.

Madelainemadeleine answered 25/2, 2017 at 18:22 Comment(1)
This question is worth it for the useful linux one-liners alone! ThanksIthunn
G
0

The method:

echo VERY_LARGE_STRING | gzip | base64 -w0

.. is limited by linux setting :

getconf ARG_MAX

Used the below and saved my day. Many thanks to Karthik1234

cat <file-name> | gzip | base64 -w0

Here is how we unzip in C# the message compressed in linux Note: You may need to remove the last byte.

static byte[] Decompress(byte[] gzip)
{
    // Create a GZIP stream with decompression mode.
    // ... Then create a buffer and write into while reading from the GZIP stream.
    using (GZipStream stream = new GZipStream(new MemoryStream(gzip),
    CompressionMode.Decompress))
    {
        const int size = 4096;
        byte[] buffer = new byte[size];
        using (MemoryStream memory = new MemoryStream())
        {
            int count = 0;
            do
            {
                count = stream.Read(buffer, 0, size);
                if (count > 0)
                {
                memory.Write(buffer, 0, count);
                }
            }
            while (count > 0);
            return memory.ToArray();
        }
    }
}
Grantor answered 24/1, 2020 at 0:4 Comment(0)
P
0
SELECT 
    p.ProjectID,
    p.ProjectName,
    (SELECT COUNT(*) FROM PMS_CRM_ERROR_LOG e WHERE e.ProjectID = p.ProjectID) AS ErrorCount,
    (SELECT COUNT(*) FROM PMS_Project_Status_Log s WHERE s.ProjectID = p.ProjectID) AS StatusCount
FROM 
    PMS_Project p;
Parvenu answered 18/7 at 4:58 Comment(1)
Thank you for contributing to the Stack Overflow community. This may be a correct answer, but it’d be really useful to provide additional explanation of your code so developers can understand your reasoning. This is especially useful for new developers who aren’t as familiar with the syntax or struggling to understand the concepts. Would you kindly edit your answer to include additional details for the benefit of the community?Lynwoodlynx

© 2022 - 2024 — McMap. All rights reserved.