zoukankan      html  css  js  c++  java
  • Zlib Usage

    Zlib official website is www.zlib.net

    References

    开源代码:http://www.zlib.net/
    zlib使用手册:http://www.zlib.net/manual.html
    zlib wince版:http://www.tenik.co.jp/~adachi/wince/

    Zlib dll named as Zlib1.dll

    Before version 1.2.4 there is folder named “project”, in which vc6 project file “.dsw” could be used to compile the static library.

    Using static library for Zlib 1.2.4

    However, after 1.2.4, this folder was removed. Here is the url for downloading source codef for zlib1.2.4

    Steps:

    • Extract the zip, open projects\visualc6\zlib.dsp in Visual Studio (I used 2005) and compile “LIB Release” (and optionally “LIB Debug”)
    • Copy zlib.h and zconf.h from “include” to your Visual Studio “include” directory, and zlib.lib (and zlibd.lib if you made it) to your Visual Studio “lib” directory.
    • On 64 bit Windows, with Visual Studio 2005, this is “C:\Program Files (x86)\Microsoft Visual Studio 8\VC\” so adjust for your version of Visual Studio.
    • You now just need to add “zlib.lib” to your “Linker -> Input -> Additional Dependencies” line in your C++ project configuration to use it (and optionally zlibd.lib for the debug version).

    Using static library for Zlib after 1.2.4

    follow readme.txt under contrib\vstudio directory.

    DLLs usage for Zlib

    zlibwapi.dll uses the WINAPI calling convention for the exported functions, and includes the minizip functionality.

    zlib1.dll is exporting the functions using the CDECL convention.

    the former dll library will be created by the zlibvc project which is included in the zlib.sln solution under contrib\vstudio

    the later dll library will be created by the official

    How to compile Zlib on windows

    For win32 version

    using visual studio command tools to run contrib\masmx86\bld_ml32.bat, and then open the solution contrib\vstudio\vc9 or contrib\vstudio\vc10. That depends on which visual studio version(vc9 for visual studio 2008, vc10 for visual studio 2010).

    project “zlibvc” for dynamic library; project “zlibstat” for static library.

    For x64 version

    using visual studio command tools(x64 cross or x64) to run contrib\masmx64\bld_ml64.bat, and then follow the same path like win32 version to open the solution and choose the compilatoin configurtion to change as x64.

    Done

    MiniZip and Zlib

    Usage for Zlib

    Decompress

    	int CZipFileDecoder::UnCompress(const char * src, const char * dst)
    	{
    		char uSorceBuffer[102400] = {0}; 
    		FILE* fin = nullptr;  
    		FILE* fout = nullptr; 
    		
    		fin = fopen(src,"r+b");
    		if (fin == nullptr)
    		{
    			cerr<<"Failed to open file:"<<src<<endl;
    			return 1;
    		}
    
    		fseek(fin,0L,SEEK_END);
    		long ufileLength = ftell(fin);
    		fseek(fin, 0L, SEEK_SET);
    
    		fread(uSorceBuffer,ufileLength,1,fin);
    		fclose(fin);
    
    		uLongf uDestBufferLen=1024000;
    		char* uDestBuffer=(char*)::calloc((uInt)uDestBufferLen, 1);
    
    		int ret = uncompress((Bytef*)uDestBuffer,(uLongf*)&uDestBufferLen,(Bytef*)uSorceBuffer,(uLongf)ufileLength);
    
    		if(ret!=Z_OK)
    		{
    			cerr<<"Failed to uncompress:"<<ret<<endl;
    			return 1;
    		}
    
    		fout = fopen(dst, "wb");
    		if (fout == nullptr)
    		{
    			free(uDestBuffer);
    			return 1;
    		}
    
    		fwrite(uDestBuffer,uDestBufferLen,1,fout);
    		fclose(fout);
    		free(uDestBuffer);
    		cout<<"Done"<<endl;
    		return 0;
    	}
  • 相关阅读:
    java集合框架复习(一)
    java集合框架复习
    java集合框架
    Mysql视图的作用及其性能分析
    php语法基础
    MySQL UNION 与 UNION ALL 语法与用法
    mysql fetch 系列函数
    跨线程传递数据解决方案 ThreadLocal 和 HystrixRequestVariableDefault
    java中带参数的try(){}语法含义是什么?
    Activiti 设置comment的用户
  • 原文地址:https://www.cnblogs.com/rogerroddick/p/3040827.html
Copyright © 2011-2022 走看看