Member 11405465 Ответов: 0

Сжатие на стороне сервера (web API) и декомпрессия на стороне клиента (javascript)


I'm working on an application which transfers huge data from server (Web API) to client (JavaScript) which takes some time over the network. So we decided to go with compression in server and decompression in client. I have used Zlib for .NET to compress my file. Below is the code which I have used for Compressing.

private void compressFile(string inFile, string outFile)
    {
        System.IO.FileStream outFileStream = new System.IO.FileStream(outFile,      System.IO.FileMode.Create);
        zlib.ZOutputStream outZStream = new zlib.ZOutputStream(outFileStream, zlib.zlibConst.Z_BEST_COMPRESSION);
        System.IO.FileStream inFileStream = new System.IO.FileStream(inFile, System.IO.FileMode.Open);
        try
        {
            CopyStream(inFileStream, outZStream);
        }
        finally
        {
            outZStream.Close();
            outFileStream.Close();
            inFileStream.Close();
        }
    }

    public static void CopyStream(System.IO.Stream input, System.IO.Stream output)
    {
        byte[] buffer = new byte[2000];
        int len;
        while ((len = input.Read(buffer, 0, 2000)) > 0)
        {
            output.Write(buffer, 0, len);
        }
        output.Flush();
    }

It has successfully compressed the data and I'm writing the compressed data to a txt file in my local machine and reading the compressed content of the file and transferring it to the client side.



Please help me resolve this issue or if you could recommend me a different method that would even help!

What I have tried:

<pre>I'm trying to decompress the data in client side using Zlib. Below is the code which I'm using


var inflate = new Zlib.Inflate(response);
var output = inflate.decompress();

Но он выдает ошибку с указанием "неподдерживаемый метод сжатия".

Richard MacCutchan

public static void CopyStream(System.IO.Stream input, System.IO.Stream output)

Я не уверен, что это проблема, но второй поток - это zlib.ZOutputStream- так не следует ли вам объявить это тем же самым?

Richard MacCutchan

Смотреть также: неподдерживаемый метод сжатия-Google Search[^]

0 Ответов