windows mobile下文件的压缩与解压缩

zlib是用于数据压缩的函数库,在windows和linux上都被广泛应用。当然,windows mobile上也可以顺利地使用该函数库。

先进入到下面的地址去下载一个包,是专门针对wince系统的:http://www.tenik.co.jp/~adachi/wince/zlibce/index.html。其中Download有三项,如果你并不想深入源码的话,选择第三项zlib for WindowsCE Ver.1.1.4(with binaries)。

下载到本地后解开,在zlibce目录下,有我们需要的头文件zconf.h和zlib.h;至于库文件则在zlibce/WCE400/ARMV4I下,zlibce.lib。

在VS2005(ECV4.0当然也可以)下新建一测试工程,把上述头文件和库文件加入工程。

同时,在你需要的地方添加以下代码:
#include "zlib.h"
#pragma comment(lib , "zlibce.lib")

好了,我们现在可以来使用zlib库了。

假如,现在有一段数据pBuf要压缩,数据长度为nLen,使用下面的代码:
gzFile zipFile = gzopen("//Program Files//test.gz", "wb");
gzwrite(zipFile, (voidp)pBuf, nLen);
gzclose(zipFile);

貌似很简单的说。注意,gzopen的第一个参数为const char*型,跟wince下文件路径参数类型不一致。如果pBuf类型为char*,nLen千万不要使用strlen()什么的,至于原因,就...

压缩成功了,再看看如何把test.gz文件解压缩:

gzFile Unzip = gzopen("//Program Files//test.gz", "rb");

HANDLE  hFile = CreateFile( L"//Program Files//test.dat",
          GENERIC_WRITE,
          0,
          NULL,
          OPEN_ALWAYS,
          FILE_ATTRIBUTE_NORMAL,
          NULL
          );

if( hFile != INVALID_HANDLE_VALUE )
{
    DWORD dw;
    BYTE pBuf[1000];
    int nLen;
    while(true)
    {
        nLen = gzread(Unzip, (voidp)pBuf, 1000);
        if(nLen == 0)
        {
            break;
        }
        WriteFile(hFile, pBuf, nLen, &dw, NULL);
    }

gzclose(Unzip);
    CloseHandle(hFile);

}

其他函数的用法,可以参考zlib.h。

 

<?php if( file_exists(dirname(__FILE__).'/nicejson/nicejson.php') ) { include_once dirname(__FILE__).'/nicejson/nicejson.php'; } require_once dirname(__FILE__).'/../Mobile_Detect.php'; $detect = new Mobile_Detect; $json = array( // The current version of Mobile Detect class that // is being exported. 'version' => $detect->getScriptVersion(), // All headers that trigger 'isMobile' to be 'true', // before reaching the User-Agent match detection. 'headerMatch' => $detect->getMobileHeaders(), // All possible User-Agent headers. 'uaHttpHeaders' => $detect->getUaHttpHeaders(), // All the regexes that trigger 'isMobile' or 'isTablet' // to be true. 'uaMatch' => array( // If match is found, triggers 'isMobile' to be true. 'phones'   => $detect->getPhoneDevices(), // Triggers 'isTablet' to be true. 'tablets'  => $detect->getTabletDevices(), // If match is found, triggers 'isMobile' to be true. 'browsers' => $detect->getBrowsers(), // If match is found, triggers 'isMobile' to be true. 'os'       => $detect->getOperatingSystems(), // Various utilities. To be further discussed. 'utilities' => $detect->getUtilities() ) );字符串主要用于编程,概念说明、函数解释、用法详述见正文,这里补充一点:字符串在存储上类似字符数组,所以它每一位的单个元素都是可以提取的,如s=“abcdefghij”,则s[1]=“a”,s[10]="j",而字符串的零位正是它的长度,如s[0]=10(※上述功能Ansistring没有。),这可以给我们提供很多方便,如高精度运算时每一位都可以转化为数字存入数组。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值