EzDevInfo.com

zlib.js

compact zlib, deflate, inflate, zip library in JavaScript

Deflate compression browser compatibility and advantages over GZIP


UPDATE Feb 10 2012:

zOompf has completed some very thorough research on this very topic here. It trumps any findings below.


UPDATE Sept 11 2010:

A testing platform has been created for this here




HTTP 1.1 definitions of GZIP and DEFLATE (zlib) for some background information:

" 'Gzip' is the gzip format, and 'deflate' is the zlib format. They should probably have called the second one 'zlib' instead to avoid confusion with the raw deflate compressed data format. While the HTTP 1.1 RFC 2616 correctly points to the zlib specification in RFC 1950 for the 'deflate' transfer encoding, there have been reports of servers and browsers that incorrectly produce or expect raw deflate data per the deflate specification in RFC 1951, most notably Microsoft products. So even though the 'deflate' transfer encoding using the zlib format would be the more efficient approach (and in fact exactly what the zlib format was designed for), using the 'gzip' transfer encoding is probably more reliable due to an unfortunate choice of name on the part of the HTTP 1.1 authors." (source: http://www.gzip.org/zlib/zlib_faq.html)

So, my question: if I send RAW deflate data with NO zlib wrapper (or gzip, for that matter) are there any modern browsers (e.g., IE6 and up, FF, Chrome, Safari, etc) that can NOT understand the raw deflate compressed data (assuming HTTP request header "Accept-Encoding" contains "deflate")?

Deflate data will ALWAYS be a few bytes smaller than GZIP.

If all these browsers can successfully decode the data, what downsides are there to sending RAW deflate instead of zlib?



UPDATE Sept 11 2010:

A testing platform has been created for this here


Source: (StackOverflow)

Python decompressing gzip chunk-by-chunk

I've a memory- and disk-limited environment where I need to decompress the contents of a gzip file sent to me in string-based chunks (over xmlrpc binary transfer). However, using the zlib.decompress() or zlib.decompressobj()/decompress() both barf over the gzip header. I've tried offsetting past the gzip header (documented here), but still haven't managed to avoid the barf. The gzip library itself only seems to support decompressing from files.

The following snippet gives a simplified illustration of what I would like to do (except in real life the buffer will be filled from xmlrpc, rather than reading from a local file):

#! /usr/bin/env python

import zlib

CHUNKSIZE=1000

d = zlib.decompressobj()

f=open('23046-8.txt.gz','rb')
buffer=f.read(CHUNKSIZE)

while buffer:
  outstr = d.decompress(buffer)
  print(outstr)
  buffer=f.read(CHUNKSIZE)

outstr = d.flush()
print(outstr)

f.close()

Unfortunately, as I said, this barfs with:

Traceback (most recent call last):
  File "./test.py", line 13, in <module>
    outstr = d.decompress(buffer)
zlib.error: Error -3 while decompressing: incorrect header check 

Theoretically, I could feed my xmlrpc-sourced data into a StringIO and then use that as a fileobj for gzip.GzipFile(), however, in real life, I don't have memory available to hold the entire file contents in memory as well as the decompressed data. I really do need to process it chunk-by-chunk.

The fall-back would be to change the compression of my xmlrpc-sourced data from gzip to plain zlib, but since that impacts other sub-systems I'd prefer to avoid it if possible.

Any ideas?


Source: (StackOverflow)

Advertisements

When compressing and encrypting, should I compress first, or encrypt first?

If I were to AES-encrypt a file, and then ZLIB-compress it, would the compression be less efficient than if I first compressed and then encrypted?

In other words, should I compress first or encrypt first, or does it matter?


Source: (StackOverflow)

Python: Inflate and Deflate implementations

I am interfacing with a server that requires that data sent to it is compressed with Deflate algorithm (Huffman encoding + LZ77) and also sends data that I need to Inflate.

I know that Python includes Zlib, and that the C libraries in Zlib support calls to Inflate and Deflate, but these apparently are not provided by the Python Zlib module. It does provide Compress and Decompress, but when I make a call such as the following:

result_data = zlib.decompress( base64_decoded_compressed_string )

I receive the following error:

Error -3 while decompressing data: incorrect header check

Gzip does no better; when making a call such as:

result_data = gzip.GzipFile( fileobj = StringIO.StringIO( base64_decoded_compressed_string ) ).read()

I receive the error:

IOError: Not a gzipped file

which makes sense as the data is a Deflated file not a true Gzipped file.

Now I know that there is a Deflate implementation available (Pyflate), but I do not know of an Inflate implementation.

It seems that there are a few options:
1. Find an existing implementation (ideal) of Inflate and Deflate in Python
2. Write my own Python extension to the zlib c library that includes Inflate and Deflate
3. Call something else that can be executed from the command line (such as a Ruby script, since Inflate/Deflate calls in zlib are fully wrapped in Ruby)
4. ?

I am seeking a solution, but lacking a solution I will be thankful for insights, constructive opinions, and ideas.

Additional information: The result of deflating (and encoding) a string should, for the purposes I need, give the same result as the following snippet of C# code, where the input parameter is an array of UTF bytes corresponding to the data to compress:

public static string DeflateAndEncodeBase64(byte[] data)
{
    if (null == data || data.Length < 1) return null;
    string compressedBase64 = "";

    //write into a new memory stream wrapped by a deflate stream
    using (MemoryStream ms = new MemoryStream())
    {
        using (DeflateStream deflateStream = new DeflateStream(ms, CompressionMode.Compress, true))
        {
            //write byte buffer into memorystream
            deflateStream.Write(data, 0, data.Length);
            deflateStream.Close();

            //rewind memory stream and write to base 64 string
            byte[] compressedBytes = new byte[ms.Length];
            ms.Seek(0, SeekOrigin.Begin);
            ms.Read(compressedBytes, 0, (int)ms.Length);
            compressedBase64 = Convert.ToBase64String(compressedBytes);
        }
    }
    return compressedBase64;
}

Running this .NET code for the string "deflate and encode me" gives the result "7b0HYBxJliUmL23Ke39K9UrX4HShCIBgEyTYkEAQ7MGIzeaS7B1pRyMpqyqBymVWZV1mFkDM7Z28995777333nvvvfe6O51OJ/ff/z9cZmQBbPbOStrJniGAqsgfP358Hz8iZvl5mbV5mi1nab6cVrM8XeT/Dw=="

When "deflate and encode me" is run through the Python Zlib.compress() and then base64 encoded, the result is "eJxLSU3LSSxJVUjMS1FIzUvOT0lVyE0FAFXHB6k=".

It is clear that zlib.compress() is not an implementation of the same algorithm as the standard Deflate algorithm.

More Information:

The first 2 bytes of the .NET deflate data ("7b0HY..."), after b64 decoding are 0xEDBD, which does not correspond to Gzip data (0x1f8b), BZip2 (0x425A) data, or Zlib (0x789C) data.

The first 2 bytes of the Python compressed data ("eJxLS..."), after b64 decoding are 0x789C. This is a Zlib header.

SOLVED
To handle the raw deflate and inflate, without header and checksum, the following things needed to happen:

On deflate/compress: strip the first two bytes (header) and the last four bytes (checksum).
On inflate/decompress: there is a second argument for window size. If this value is negative it suppresses headers.
here are my methods currently, including the base64 encoding/decoding - and working properly:

import zlib
import base64

def decode_base64_and_inflate( b64string ):
    decoded_data = base64.b64decode( b64string )
    return zlib.decompress( decoded_data , -15)

def deflate_and_base64_encode( string_val ):
    zlibbed_str = zlib.compress( string_val )
    compressed_string = zlibbed_str[2:-4]
    return base64.b64encode( compressed_string )

Source: (StackOverflow)

How to compress a buffer with zlib?

There is a usage example at the zlib website: http://www.zlib.net/zlib_how.html

However in the example they are compressing a file. I would like to compress a binary data stored in a buffer in memory. I don't want to save the compressed buffer to disk either.

Basically here is my buffer:

fIplImageHeader->imageData = (char*)imageIn->getFrame();

How can I compress it with zlib?

I would appreciate some code example of how to do that.


Source: (StackOverflow)

Difference between mod_deflate and zlib output_compression

Can anyone tell me the difference between using mod_deflate and zlib output_compression?

I understand that zlib is done in PHP and mod_deflate is done in Apace, my .htaccess file looks like:

php_flag zlib.output_compression On

or:

SetOutputFilter DEFLATE
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html
SetEnvIfNoCase Request_URI \
\.(?:gif|jpe?g|png|gif)$ no-gzip dont-vary
Header append Vary User-Agent env=!dont-vary

Advantages/disadvantages of either?


Source: (StackOverflow)

Unresolved externals despite linking in zlib.lib

I've been trying to compile an application which utilizes zlib compression in VC++ 2010.

I get the

error LNK2019: unresolved external symbol _inflateInit2_ referenced in function ...

error message, which wouldn't be unusual if I didn't link the lib. I link the static release zlib library.

I've managed to get this exact same configuration of libs and headers working perfectly in different solutions and hence this behavior is greatly unexpected.

Any ideas will be appreciated.

UPDATE: Linker command line /OUT:"C:\Documents and Settings\Suthke\My Documents\Visual Studio 2010\Projects\SBRapGen2\Debug\SBRapGen2.exe" /INCREMENTAL /NOLOGO "zlib.lib" "kernel32.lib" "user32.lib" "gdi32.lib" "winspool.lib" "comdlg32.lib" "advapi32.lib" "shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib" "odbc32.lib" "odbccp32.lib" /MANIFEST /ManifestFile:"Debug\SBRapGen2.exe.intermediate.manifest" /ALLOWISOLATION /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /DEBUG /PDB:"C:\Documents and Settings\Suthke\My Documents\Visual Studio 2010\Projects\SBRapGen2\Debug\SBRapGen2.pdb" /SUBSYSTEM:CONSOLE /PGD:"C:\Documents and Settings\Suthke\My Documents\Visual Studio 2010\Projects\SBRapGen2\Debug\SBRapGen2.pgd" /TLBID:1 /DYNAMICBASE /NXCOMPAT /MACHINE:X86 /ERRORREPORT:QUEUE

UPDATE 2: Verbose linker output:

1>------ Build started: Project: SBRapGen2, Configuration: Release Win32 ------ 1>
1> Starting pass 1 1> Processed /DEFAULTLIB:uuid.lib 1> Processed /DEFAULTLIB:msvcprt 1> Processed /DEFAULTLIB:zlib.lib 1> Processed /DEFAULTLIB:MSVCRT 1> Processed /DEFAULTLIB:OLDNAMES 1>
1> Searching libraries 1> Searching C:\Program Files\Microsoft Visual Studio 10.0\VC\lib\zlib.lib: 1> Searching C:\Program Files\Microsoft SDKs\Windows\v7.0A\lib\kernel32.lib: 1> Searching C:\Program Files\Microsoft SDKs\Windows\v7.0A\lib\user32.lib: 1> Searching C:\Program Files\Microsoft SDKs\Windows\v7.0A\lib\gdi32.lib: 1> Searching C:\Program Files\Microsoft SDKs\Windows\v7.0A\lib\winspool.lib: 1> Searching C:\Program Files\Microsoft SDKs\Windows\v7.0A\lib\comdlg32.lib: 1> Searching C:\Program Files\Microsoft SDKs\Windows\v7.0A\lib\advapi32.lib: 1> Searching C:\Program Files\Microsoft SDKs\Windows\v7.0A\lib\shell32.lib: 1> Searching C:\Program Files\Microsoft SDKs\Windows\v7.0A\lib\ole32.lib: 1> Searching C:\Program Files\Microsoft SDKs\Windows\v7.0A\lib\oleaut32.lib: 1> Searching C:\Program Files\Microsoft SDKs\Windows\v7.0A\lib\uuid.lib: 1> Searching C:\Program Files\Microsoft SDKs\Windows\v7.0A\lib\odbc32.lib: 1> Searching C:\Program Files\Microsoft SDKs\Windows\v7.0A\lib\odbccp32.lib: 1> Searching C:\Program Files\Microsoft Visual Studio 10.0\VC\lib\msvcprt.lib: 1> Searching C:\Program Files\Microsoft Visual Studio 10.0\VC\lib\MSVCRT.lib: 1> Found @__security_check_cookie@4 1> Referenced in SBRapGen2.obj 1> Loaded MSVCRT.lib(secchk.obj) 1> Found __imp__sprintf 1> Referenced in SBRapGen2.obj 1> Loaded MSVCRT.lib(MSVCR100.dll) 1> Found __imp__ceil 1> Referenced in SBRapGen2.obj 1> Loaded MSVCRT.lib(MSVCR100.dll) 1> Found __imp__free 1> Referenced in SBRapGen2.obj 1> Loaded MSVCRT.lib(MSVCR100.dll) 1> Found __imp__malloc 1> Referenced in SBRapGen2.obj 1> Loaded MSVCRT.lib(MSVCR100.dll) 1> Found __imp__printf 1> Referenced in SBRapGen2.obj 1> Loaded MSVCRT.lib(MSVCR100.dll) 1> Found __imp__fopen 1> Referenced in SBRapGen2.obj 1> Loaded MSVCRT.lib(MSVCR100.dll) 1> Found __imp__fread 1> Referenced in SBRapGen2.obj 1> Loaded MSVCRT.lib(MSVCR100.dll) 1> Found __imp__fwrite 1> Referenced in SBRapGen2.obj 1> Loaded MSVCRT.lib(MSVCR100.dll) 1> Found __imp__ftell 1> Referenced in SBRapGen2.obj 1> Loaded MSVCRT.lib(MSVCR100.dll) 1> Found __imp__fseek 1> Referenced in SBRapGen2.obj 1> Loaded MSVCRT.lib(MSVCR100.dll) 1> Found __imp__fclose 1> Referenced in SBRapGen2.obj 1> Loaded MSVCRT.lib(MSVCR100.dll) 1> Found _mainCRTStartup 1> Loaded MSVCRT.lib(crtexe.obj) 1> Found ___report_gsfailure 1> Referenced in MSVCRT.lib(secchk.obj) 1> Loaded MSVCRT.lib(gs_report.obj) 1> Found ___security_cookie 1> Referenced in MSVCRT.lib(secchk.obj) 1> Referenced in MSVCRT.lib(gs_report.obj) 1> Loaded MSVCRT.lib(gs_cookie.obj) 1> Found __IMPORT_DESCRIPTOR_MSVCR100 1> Referenced in MSVCRT.lib(MSVCR100.dll) 1> Referenced in MSVCRT.lib(MSVCR100.dll) 1> Referenced in MSVCRT.lib(MSVCR100.dll) 1> Referenced in MSVCRT.lib(MSVCR100.dll) 1> Referenced in MSVCRT.lib(MSVCR100.dll) 1> Referenced in MSVCRT.lib(MSVCR100.dll) 1> Referenced in MSVCRT.lib(MSVCR100.dll) 1> Referenced in MSVCRT.lib(MSVCR100.dll) 1> Referenced in MSVCRT.lib(MSVCR100.dll) 1> Referenced in MSVCRT.lib(MSVCR100.dll) 1> Referenced in MSVCRT.lib(MSVCR100.dll) 1> Loaded MSVCRT.lib(MSVCR100.dll) 1> Found ___CxxSetUnhandledExceptionFilter 1> Referenced in MSVCRT.lib(crtexe.obj) 1> Loaded MSVCRT.lib(unhandld.obj) 1> Found __amsg_exit 1> Referenced in MSVCRT.lib(crtexe.obj) 1> Loaded MSVCRT.lib(MSVCR100.dll) 1> Found __imp____getmainargs 1> Referenced in MSVCRT.lib(crtexe.obj) 1> Loaded MSVCRT.lib(MSVCR100.dll) 1> Found __dowildcard 1> Referenced in MSVCRT.lib(crtexe.obj) 1> Loaded MSVCRT.lib(wildcard.obj) 1> Found __newmode 1> Referenced in MSVCRT.lib(crtexe.obj) 1> Loaded MSVCRT.lib(_newmode.obj) 1> Found _atexit 1> Referenced in MSVCRT.lib(crtexe.obj) 1> Loaded MSVCRT.lib(atonexit.obj) 1> Found __RTC_Terminate 1> Referenced in MSVCRT.lib(crtexe.obj) 1> Loaded MSVCRT.lib(_initsect_.obj) 1> Found __imp___cexit 1> Referenced in MSVCRT.lib(crtexe.obj) 1> Loaded MSVCRT.lib(MSVCR100.dll) 1> Found __imp___exit 1> Referenced in MSVCRT.lib(crtexe.obj) 1> Loaded MSVCRT.lib(MSVCR100.dll) 1> Found __XcptFilter 1> Referenced in MSVCRT.lib(crtexe.obj) 1> Loaded MSVCRT.lib(MSVCR100.dll) 1> Found __imp__exit 1> Referenced in MSVCRT.lib(crtexe.obj) 1> Loaded MSVCRT.lib(MSVCR100.dll) 1> Found __imp____initenv 1> Referenced in MSVCRT.lib(crtexe.obj) 1> Loaded MSVCRT.lib(MSVCR100.dll) 1> Found __IsNonwritableInCurrentImage 1> Referenced in MSVCRT.lib(crtexe.obj) 1> Loaded MSVCRT.lib(pesect.obj) 1> Found __initterm 1> Referenced in MSVCRT.lib(crtexe.obj) 1> Loaded MSVCRT.lib(MSVCR100.dll) 1> Found ___xc_a 1> Referenced in MSVCRT.lib(crtexe.obj) 1> Loaded MSVCRT.lib(cinitexe.obj) 1> Processed /DEFAULTLIB:kernel32.lib 1> Processed /DISALLOWLIB:libcmt.lib 1> Processed /DISALLOWLIB:libcmtd.lib 1> Processed /DISALLOWLIB:msvcrtd.lib 1> Found __initterm_e 1> Referenced in MSVCRT.lib(crtexe.obj) 1> Loaded MSVCRT.lib(MSVCR100.dll) 1> Found ___native_startup_state 1> Referenced in MSVCRT.lib(crtexe.obj) 1> Loaded MSVCRT.lib(natstart.obj) 1> Found __SEH_epilog4 1> Referenced in MSVCRT.lib(crtexe.obj) 1> Referenced in MSVCRT.lib(atonexit.obj) 1> Loaded MSVCRT.lib(sehprolg4.obj) 1> Found __except_handler4 1> Referenced in MSVCRT.lib(crtexe.obj) 1> Referenced in MSVCRT.lib(atonexit.obj) 1> Referenced in MSVCRT.lib(pesect.obj) 1> Referenced in MSVCRT.lib(sehprolg4.obj) 1> Loaded MSVCRT.lib(chandler4gs.obj) 1> Found __imp___configthreadlocale 1> Referenced in MSVCRT.lib(crtexe.obj) 1> Loaded MSVCRT.lib(MSVCR100.dll) 1> Found ___globallocalestatus 1> Referenced in MSVCRT.lib(crtexe.obj) 1> Loaded MSVCRT.lib(xthdloc.obj) 1> Found __setdefaultprecision 1> Referenced in MSVCRT.lib(crtexe.obj) 1> Loaded MSVCRT.lib(fp8.obj) 1> Found __imp____setusermatherr 1> Referenced in MSVCRT.lib(crtexe.obj) 1> Loaded MSVCRT.lib(MSVCR100.dll) 1> Found __matherr 1> Referenced in MSVCRT.lib(crtexe.obj) 1> Loaded MSVCRT.lib(merr.obj) 1> Found __setargv 1> Referenced in MSVCRT.lib(crtexe.obj) 1> Loaded MSVCRT.lib(dllargv.obj) 1> Found __commode 1> Referenced in MSVCRT.lib(crtexe.obj) 1> Loaded MSVCRT.lib(xncommod.obj) 1> Found __imp___commode 1> Referenced in MSVCRT.lib(crtexe.obj) 1> Loaded MSVCRT.lib(MSVCR100.dll) 1> Found __imp___fmode 1> Referenced in MSVCRT.lib(crtexe.obj) 1> Loaded MSVCRT.lib(MSVCR100.dll) 1> Found __fmode 1> Referenced in MSVCRT.lib(crtexe.obj) 1> Loaded MSVCRT.lib(xtxtmode.obj) 1> Found __imp____set_app_type 1> Referenced in MSVCRT.lib(crtexe.obj) 1> Loaded MSVCRT.lib(MSVCR100.dll) 1> Found ___security_init_cookie 1> Referenced in MSVCRT.lib(crtexe.obj) 1> Loaded MSVCRT.lib(gs_support.obj) 1> Found __crt_debugger_hook 1> Referenced in MSVCRT.lib(gs_report.obj) 1> Loaded MSVCRT.lib(MSVCR100.dll) 1> Found __NULL_IMPORT_DESCRIPTOR 1> Referenced in MSVCRT.lib(MSVCR100.dll) 1> Loaded MSVCRT.lib(MSVCR100.dll) 1> Found MSVCR100_NULL_THUNK_DATA 1> Referenced in MSVCRT.lib(MSVCR100.dll) 1> Loaded MSVCRT.lib(MSVCR100.dll) 1> Found "void __cdecl terminate(void)" (?terminate@@YAXXZ) 1> Referenced in MSVCRT.lib(unhandld.obj) 1> Loaded MSVCRT.lib(MSVCR100.dll) 1> Found __unlock 1> Referenced in MSVCRT.lib(atonexit.obj) 1> Loaded MSVCRT.lib(MSVCR100.dll) 1> Found ___dllonexit 1> Referenced in MSVCRT.lib(atonexit.obj) 1> Loaded MSVCRT.lib(MSVCR100.dll) 1> Found __lock 1> Referenced in MSVCRT.lib(atonexit.obj) 1> Loaded MSVCRT.lib(MSVCR100.dll) 1> Found __imp___onexit 1> Referenced in MSVCRT.lib(atonexit.obj) 1> Loaded MSVCRT.lib(MSVCR100.dll) 1> Found __except_handler4_common 1> Referenced in MSVCRT.lib(chandler4gs.obj) 1> Loaded MSVCRT.lib(MSVCR100.dll) 1> Found __invoke_watson 1> Referenced in MSVCRT.lib(fp8.obj) 1> Loaded MSVCRT.lib(MSVCR100.dll) 1> Found __controlfp_s 1> Referenced in MSVCRT.lib(fp8.obj) 1> Loaded MSVCRT.lib(MSVCR100.dll) 1> Searching C:\Program Files\Microsoft Visual Studio 10.0\VC\lib\OLDNAMES.lib: 1> Searching C:\Program Files\Microsoft Visual Studio 10.0\VC\lib\zlib.lib: 1> Searching C:\Program Files\Microsoft SDKs\Windows\v7.0A\lib\kernel32.lib: 1> Found __imp__InterlockedExchange@8 1> Referenced in MSVCRT.lib(crtexe.obj) 1> Loaded kernel32.lib(KERNEL32.dll) 1> Found __imp__Sleep@4 1> Referenced in MSVCRT.lib(crtexe.obj) 1> Loaded kernel32.lib(KERNEL32.dll) 1> Found __imp__InterlockedCompareExchange@12 1> Referenced in MSVCRT.lib(crtexe.obj) 1> Loaded kernel32.lib(KERNEL32.dll) 1> Found __imp__HeapSetInformation@16 1> Referenced in MSVCRT.lib(crtexe.obj) 1> Loaded kernel32.lib(KERNEL32.dll) 1> Found __imp__EncodePointer@4 1> Referenced in MSVCRT.lib(crtexe.obj) 1> Referenced in MSVCRT.lib(atonexit.obj) 1> Loaded kernel32.lib(KERNEL32.dll) 1> Found __imp__TerminateProcess@8 1> Referenced in MSVCRT.lib(gs_report.obj) 1> Loaded kernel32.lib(KERNEL32.dll) 1> Found __imp__GetCurrentProcess@0 1> Referenced in MSVCRT.lib(gs_report.obj) 1> Loaded kernel32.lib(KERNEL32.dll) 1> Found __imp__UnhandledExceptionFilter@4 1> Referenced in MSVCRT.lib(gs_report.obj) 1> Loaded kernel32.lib(KERNEL32.dll) 1> Found __imp__SetUnhandledExceptionFilter@4 1> Referenced in MSVCRT.lib(gs_report.obj) 1> Referenced in MSVCRT.lib(unhandld.obj) 1> Loaded kernel32.lib(KERNEL32.dll) 1> Found __imp__IsDebuggerPresent@0 1> Referenced in MSVCRT.lib(gs_report.obj) 1> Loaded kernel32.lib(KERNEL32.dll) 1> Found __imp__DecodePointer@4 1> Referenced in MSVCRT.lib(atonexit.obj) 1> Loaded kernel32.lib(KERNEL32.dll) 1> Found __imp__QueryPerformanceCounter@4 1> Referenced in MSVCRT.lib(gs_support.obj) 1> Loaded kernel32.lib(KERNEL32.dll) 1> Found __imp__GetTickCount@0 1> Referenced in MSVCRT.lib(gs_support.obj) 1> Loaded kernel32.lib(KERNEL32.dll) 1> Found __imp__GetCurrentThreadId@0 1> Referenced in MSVCRT.lib(gs_support.obj) 1> Loaded kernel32.lib(KERNEL32.dll) 1> Found __imp__GetCurrentProcessId@0 1> Referenced in MSVCRT.lib(gs_support.obj) 1> Loaded kernel32.lib(KERNEL32.dll) 1> Found __imp__GetSystemTimeAsFileTime@4 1> Referenced in MSVCRT.lib(gs_support.obj) 1> Loaded kernel32.lib(KERNEL32.dll) 1> Found __IMPORT_DESCRIPTOR_KERNEL32 1> Referenced in kernel32.lib(KERNEL32.dll) 1> Referenced in kernel32.lib(KERNEL32.dll) 1> Referenced in kernel32.lib(KERNEL32.dll) 1> Referenced in kernel32.lib(KERNEL32.dll) 1> Referenced in kernel32.lib(KERNEL32.dll) 1> Referenced in kernel32.lib(KERNEL32.dll) 1> Referenced in kernel32.lib(KERNEL32.dll) 1> Referenced in kernel32.lib(KERNEL32.dll) 1> Referenced in kernel32.lib(KERNEL32.dll) 1> Referenced in kernel32.lib(KERNEL32.dll) 1> Referenced in kernel32.lib(KERNEL32.dll) 1> Referenced in kernel32.lib(KERNEL32.dll) 1> Referenced in kernel32.lib(KERNEL32.dll) 1> Referenced in kernel32.lib(KERNEL32.dll) 1> Referenced in kernel32.lib(KERNEL32.dll) 1> Referenced in kernel32.lib(KERNEL32.dll) 1> Loaded kernel32.lib(KERNEL32.dll) 1> Found KERNEL32_NULL_THUNK_DATA 1> Referenced in kernel32.lib(KERNEL32.dll) 1> Loaded kernel32.lib(KERNEL32.dll) 1> Searching C:\Program Files\Microsoft SDKs\Windows\v7.0A\lib\user32.lib: 1> Searching C:\Program Files\Microsoft SDKs\Windows\v7.0A\lib\gdi32.lib: 1> Searching C:\Program Files\Microsoft SDKs\Windows\v7.0A\lib\winspool.lib: 1> Searching C:\Program Files\Microsoft SDKs\Windows\v7.0A\lib\comdlg32.lib: 1> Searching C:\Program Files\Microsoft SDKs\Windows\v7.0A\lib\advapi32.lib: 1> Searching C:\Program Files\Microsoft SDKs\Windows\v7.0A\lib\shell32.lib: 1> Searching C:\Program Files\Microsoft SDKs\Windows\v7.0A\lib\ole32.lib: 1> Searching C:\Program Files\Microsoft SDKs\Windows\v7.0A\lib\oleaut32.lib: 1> Searching C:\Program Files\Microsoft SDKs\Windows\v7.0A\lib\uuid.lib: 1> Searching C:\Program Files\Microsoft SDKs\Windows\v7.0A\lib\odbc32.lib: 1> Searching C:\Program Files\Microsoft SDKs\Windows\v7.0A\lib\odbccp32.lib: 1> Searching C:\Program Files\Microsoft Visual Studio 10.0\VC\lib\msvcprt.lib: 1> Searching C:\Program Files\Microsoft Visual Studio 10.0\VC\lib\MSVCRT.lib: 1> Searching C:\Program Files\Microsoft Visual Studio 10.0\VC\lib\OLDNAMES.lib: 1> Searching C:\Program Files\Microsoft Visual Studio 10.0\VC\lib\zlib.lib: 1>
1> Finished searching libraries 1>
1> Finished pass 1 1>
1>SBRapGen2.obj : error LNK2001: unresolved external symbol _deflateEnd 1>SBRapGen2.obj : error LNK2001: unresolved external symbol _inflateInit2_ 1>SBRapGen2.obj : error LNK2001: unresolved external symbol _inflate 1>SBRapGen2.obj : error LNK2001: unresolved external symbol _inflateEnd 1>SBRapGen2.obj : error LNK2001: unresolved external symbol _deflate 1>SBRapGen2.obj : error LNK2001: unresolved external symbol _deflateInit2_


Source: (StackOverflow)

How are zlib, gzip and Zip related? What are is common and How are they different?

The compression algorithm used in zlib is essentially the same as that in gzip and Zip. What are gzip and Zip? How are they different and how are they same?


Source: (StackOverflow)

zlib.error: Error -3 while decompressing: incorrect header check

I have a gzip file and I am trying to read it via Python as below:

import zlib

do = zlib.decompressobj(16+zlib.MAX_WBITS)
fh = open('abc.gz', 'rb')
cdata = fh.read()
fh.close()
data = do.decompress(cdata)

it throws this error:

zlib.error: Error -3 while decompressing: incorrect header check

How can I overcome it?


Source: (StackOverflow)

How to download and unzip a zip file in memory in NodeJs?

I want to download a zip file from the internet and unzip it in memory without saving to a temporary file. How can I do this?

Here is what I tried:

var url = 'http://bdn-ak.bloomberg.com/precanned/Comdty_Calendar_Spread_Option_20120428.txt.zip';

var request = require('request'), fs = require('fs'), zlib = require('zlib');

  request.get(url, function(err, res, file) {
     if(err) throw err;
     zlib.unzip(file, function(err, txt) {
        if(err) throw err;
        console.log(txt.toString()); //outputs nothing
     });
  });

[EDIT] As, suggested, I tried using the adm-zip library and I still cannot make this work:

var ZipEntry = require('adm-zip/zipEntry');
request.get(url, function(err, res, zipFile) {
        if(err) throw err;
        var zip = new ZipEntry();
        zip.setCompressedData(new Buffer(zipFile.toString('utf-8')));
        var text = zip.getData();
        console.log(text.toString()); // fails
    });

Source: (StackOverflow)

Simple way to unzip a .zip file using zlib [duplicate]

This question already has an answer here:

Is there a simple example of how to unzip a .zip file and extract the files to a directory? I am currently using zlib, and while I understand that zlib does not directly deal with zip files, there seems to be several additional things in zlibs's "contrib" library. I noticed and read about "minizip", and after reading some documents and looking at some of the code, I do not see a simple example of how to unzip a .zip file and extract the files to a directory.

I would like to find a platform independent way of doing so, but if that is not possible then I need to find a way for windows and mac.


Source: (StackOverflow)

How do I ungzip (decompress) a NodeJS request's module gzip response body?

NodeJS: How do I unzip a gzipped body in a request's module response? I have tried several examples around the web but nothing works...

    request(url, function(err, response, body) {
        if(err) {
            handleError(err)
        } else {
            if(response.headers['content-encoding'] == 'gzip') {

                // How can I unzip the gzipped string body variable?
                // For instance, this url:
                // http://highsnobiety.com/2012/08/25/norse-projects-fall-2012-lookbook/
                // Throws error:
                // { [Error: incorrect header check] errno: -3, code: 'Z_DATA_ERROR' }
                // Yet, browser displays page fine and debugger shows its gzipped
                // And unzipped by browser fine...
                if(response.headers['content-encoding'] 
                    && response.headers['content-encoding']
                       .toLowerCase().indexOf('gzip') > -1) {   
                    var body = response.body;                    
                    zlib.gunzip(response.body, function(error, data) {
                        if(!error) {
                            response.body = data.toString();
                        } else {
                            console.log('Error unzipping:');
                            console.log(error);
                            response.body = body;
                        }
                    });
                }
            }
        }
    }

Thanks in advance for any insights...


Source: (StackOverflow)

Linking with libpng & zlib?

I'm trying to compile a project that uses both libjpeg and libpng. I know that libpng needs zlib, so I compiled all the three independently and put them (libjpeg.a, libpng.a and libz.a) on a folder called linrel32. What I execute then is:

g++ -Llinrel32/ program.cpp otherfile.cpp -o linrel32/executable -Izlib/ -Ilpng140/ -Ijpeg/ -lpthread -lX11 -O2 -DLINUX -s -lz -lpng -ljpeg

So I include the three libraries. Still, the linker complains:

linrel32//libpng.a(png.o): In function `png_calculate_crc':
png.c:(.text+0x97d): undefined reference to `crc32'
linrel32//libpng.a(png.o): In function `png_reset_crc':
png.c:(.text+0x9be): undefined reference to `crc32'
linrel32//libpng.a(png.o): In function `png_reset_zstream':
png.c:(.text+0x537): undefined reference to `inflateReset'
linrel32//libpng.a(pngread.o): In function `png_read_destroy':
pngread.c:(.text+0x6f4): undefined reference to `inflateEnd'
linrel32//libpng.a(pngread.o): In function `png_read_row':
pngread.c:(.text+0x1267): undefined reference to `inflate'
linrel32//libpng.a(pngread.o): In function `png_create_read_struct_2':

(... you get the idea :D)

collect2: ld returned 1 exit status

I know the missing functions are from zlib, and I'm adding zlib there. Opened libz.a and it seems to have a good structure. Recompiled it, everything looks fine. But it is not...

I don't know, is likely that the problem is trivial, and what I need is to sleep for a while. But still, if you could help me to figure out this thing ...


Source: (StackOverflow)

Installing latest 1.44 boost library under ubuntu 10.04

I have ubuntu 10.04 and want to install the latest boost library 1.44_0

I downloaded the tar.gz file and unpacked it into /usr/local/boost_1_44_0

I already have the boost 1.40 version install from synaptic.

So I want to compile and link against 1.44 because I'm wanting to use some new libraries that are not in the older version such as the property tree.

But, I'm having some issues getting it going.

Ran sudo ./bootstrap.sh (that went fine)

Ran ./bjam install There were errors with bzip2.

gcc.compile.c++ bin.v2/libs/iostreams/build/gcc-4.4.3/release/threading-multi/file_descriptor.o
gcc.compile.c++ bin.v2/libs/iostreams/build/gcc-4.4.3/release/threading-multi/mapped_file.o
gcc.compile.c++ bin.v2/libs/iostreams/build/gcc-4.4.3/release/threading-multi/zlib.o
gcc.compile.c++ bin.v2/libs/iostreams/build/gcc-4.4.3/release/threading-multi/gzip.o
gcc.compile.c++ bin.v2/libs/iostreams/build/gcc-4.4.3/release/threading-multi/bzip2.o
libs/iostreams/src/bzip2.cpp:20:56: error: bzlib.h: No such file or directory
libs/iostreams/src/bzip2.cpp:31: error: ‘BZ_OK’ was not declared in this scope
libs/iostreams/src/bzip2.cpp:32: error: ‘BZ_RUN_OK’ was not declared in this scope
...

Although I'm not using bzip2 so I'm not worried.

But then a short time later during the compile, screens full of errors appear. Too many to list here, but they often have python in the name.

... on::list]’: ./boost/python/str.hpp:285: instantiated from ‘boost::python::str boost::python::str::join(const T&) const [with T = boost::python::list]’ libs/python/src/object/function_doc_signature.cpp:321: instantiated from here ./boost/python/object_core.hpp:334: error: ‘object_base_initializer’ was not declared in this scope

    "g++"  -ftemplate-depth-128 -O3 -finline-functions -Wno-inline -Wall -pthread -fPIC  -DBOOST_ALL_NO_LIB=1 -DBOOST_PYTHON_SOURCE -DNDEBUG  -I"." -I"/usr/include/python2.6" -c -o "bin.v2/libs/python/build/gcc-4.4.3/release/threading-multi/object/function_doc_signature.o" "libs/python/src/object/function_doc_signature.cpp"

...failed gcc.compile.c++ bin.v2/libs/python/build/gcc-4.4.3/release/threading-multi/object/function_doc_signature.o...
...skipped <pstage/lib>libboost_python.so.1.44.0 for lack of <pbin.v2/libs/python/build/gcc-4.4.3/release/threading-multi>numeric.o...
...skipped <pstage/lib>libboost_python.so for lack of <pstage/lib>libboost_python.so.1.44.0...
gcc.compile.c++ bin.v2/libs/random/build/gcc-4.4.3/release/threading-multi/random_device.o

First off, why so many errors? There are other ones too and too many to list here.

But the main issue I have is that I want to link to the libraries, but they are not placed where expected. I thought they would be in boost_1_44_0/libs, but they are not found. I did find some .a files scattered around though.

Am I just building this whole thing wrong?


Source: (StackOverflow)

Error Deflate And Inflate With zLib

I'm trying to compile the zpipe.c example in my Linux(Ubuntu 8.04) with gcc, but I'm getting some errors, take a look:

[ubuntu@eeepc:~/Desktop] gcc zpipe.c
/tmp/ccczEQxz.o: In function `def':
zpipe.c:(.text+0x65): undefined reference to `deflateInit_'
zpipe.c:(.text+0xd3): undefined reference to `deflateEnd'
zpipe.c:(.text+0x150): undefined reference to `deflate'
zpipe.c:(.text+0x1e8): undefined reference to `deflateEnd'
zpipe.c:(.text+0x27b): undefined reference to `deflateEnd'
/tmp/ccczEQxz.o: In function `inf':
zpipe.c:(.text+0x314): undefined reference to `inflateInit_'
zpipe.c:(.text+0x382): undefined reference to `inflateEnd'
zpipe.c:(.text+0x3d7): undefined reference to `inflate'
zpipe.c:(.text+0x44b): undefined reference to `inflateEnd'
zpipe.c:(.text+0x4c1): undefined reference to `inflateEnd'
zpipe.c:(.text+0x4f6): undefined reference to `inflateEnd'
collect2: ld returned 1 exit status
[ubuntu@eeepc:~/Desktop]

Remember that I've installed zLib-dev correctly, but why i'm getting this errors?


Source: (StackOverflow)