IOS_49_使用objective-zip解壓檔案
1.從github上將objective-zip下載後,拖動到專案裡,如圖所示
2.控制器程式碼如下所示
執行效果如下:// // ViewController.m // tempOCZIP // // Created by beyond on 2010/06/07. // Copyright © 2010年 beyond. All rights reserved. // #import "ViewController.h" #import "Objective-Zip.h" @interface ViewController () @end @implementation ViewController static int BUFFER_SIZE = 1024; - (void)viewDidLoad { [super viewDidLoad]; [self startUnZip]; } - (void)startUnZip { NSString *filePath = [[NSBundle mainBundle]pathForResource:@"abc.zip" ofType:nil]; NSString *unzipPath = [self tempUnzipPathInDoc]; NSLog(@"sg__%@",unzipPath); [self decompressFileFromPath:filePath toPath:unzipPath]; } - (void)decompressFileFromPath:(NSString *)from toPath:(NSString *)to{ @try { OZZipFile *unzipFile = [[OZZipFile alloc] initWithFileName:from mode:OZZipFileModeUnzip]; //解壓是否完成 BOOL unzipFinished = NO; while (!unzipFinished) { //獲取當前遍歷到的檔案資訊 OZFileInZipInfo *info = [unzipFile getCurrentFileInZipInfo]; OZZipReadStream *stream = [unzipFile readCurrentFileInZip]; NSMutableData *buffer = [[NSMutableData alloc] initWithLength:BUFFER_SIZE]; // unzip files to the write path NSString *writePath = [to stringByAppendingPathComponent:info.name]; if ([info.name hasSuffix:@"/"]) { //建立目錄 NSFileManager *fileManager = [NSFileManager defaultManager]; [fileManager createDirectoryAtPath:writePath withIntermediateDirectories:YES attributes:nil error:nil]; // [MFFileToolkit createDrectoryIfNeeded:writePath]; }else{ //建立檔案 NSFileManager *fileManager = [NSFileManager defaultManager]; [fileManager createFileAtPath:writePath contents:nil attributes:nil]; // [MFFileToolkit createFilePath:writePath]; //create fileHanderler to manage writing data to specified path, before writing data, move //the cusor to the end of the file first. NSFileHandle *fileHandler = [NSFileHandle fileHandleForWritingAtPath:writePath]; [buffer setLength:0]; do { [buffer setLength:BUFFER_SIZE]; int bytesRead = [stream readDataWithBuffer:buffer]; //每次讀取BUFFER_SIZE大小的資料,如果讀出的資料大小>0,就繼續迴圈讀取資料, //直到讀到的資料大小<= 0時,退出迴圈,當前遍歷的檔案已解壓完畢 if (bytesRead > 0) { [buffer setLength:bytesRead]; [fileHandler seekToEndOfFile]; [fileHandler writeData:buffer]; }else{ break; } } while (YES); [fileHandler closeFile]; } [stream finishedReading]; buffer = nil; // Check if we should continue reading unzipFinished = ![unzipFile goToNextFileInZip]; } } @catch (OZZipException *exception) { @throw exception; } } - (NSString *)tempUnzipPathInDoc { NSString *path = [NSString stringWithFormat:@"%@/\%@", NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0], [NSUUID UUID].UUIDString]; NSURL *url = [NSURL fileURLWithPath:path]; NSError *error = nil; [[NSFileManager defaultManager] createDirectoryAtURL:url withIntermediateDirectories:YES attributes:nil error:&error]; if (error) { return nil; } return url.path; } @end
相關推薦
壓縮包解密,zip解壓檔案解密,找回密碼,RAR破解密碼工具,壓縮包解密,解壓檔案解密,檔案軟體RA
壓縮包解密,zip解壓檔案解密,找回密碼,RAR破解密碼工具,壓縮包解密,解壓檔案解密,檔案軟體RAR破解密碼工具免費下載。 目前我見過的最好用的,破解密碼速度最快的軟體,沒有之一,附帶教程,親測好用!!! 下載地址:https://pan.baidu.com/s/1QUwcvwGtwL4StNfSO
nodejs adm-zip 解壓檔案 中文檔名亂碼
最近的一個專案需要上傳zip檔案到伺服器,然後解壓到當前目錄,最初選用unzip包進行解壓,開始使用的時候不知道這個包有監聽函式,認為完全是同步的。實際是有完成解壓監聽函式的。使用adm-zip的時候是同步的,滿足需要,但是如果資料夾種有中文檔名的時候在windows下壓縮
IOS_49_使用objective-zip解壓檔案
1.從github上將objective-zip下載後,拖動到專案裡,如圖所示2.控制器程式碼如下所示// // ViewController.m // tempOCZIP // // Created by beyond on 2010/06/07. // Copyr
linux下 zip解壓 tar解壓 gz解壓 bz2等各種解壓檔案命令
大致總結了一下linux下各種格式的壓縮包的壓縮、解壓方法。但是部分方法我沒有用到,也就不全,希望大家幫我補充,我將隨時修改完善,謝謝! .tar 解包:tar xvf FileName.tar 打包:tar cvf FileName.tar DirNam
Centos7 zip解壓和unzip壓縮檔案
1、安裝zip、unzip應用 yum install zip unzip 2、壓縮和解壓檔案 以下命令均在/home目錄下操作 cd /home #進入/home目錄 a、把/home目錄下面的mydata目錄壓縮為mydata.zip zip -
Zip4j解壓檔案
使用 zip4j 可以快速對檔案進行解壓縮處理 更多精彩 更多技術部落格,請移步 asing1elife’s blog 官網 zip4j 特性 支援Zip檔案的建立、新增、解壓、更新、移除 可讀寫有密碼保護的Zip檔案
java壓縮解壓檔案
記錄一下,公司在伺服器中,需要對檔案進行壓縮,然後給使用者下載故記錄一下: import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOExc
php 解壓檔案與壓縮檔案
配置環境變數 然後cmd 輸入 php -m 檢視是否有zip 選項 沒有的話zip功能將無法使用 function zip_file(string $filename) { if (!is_file($filename)) { return false;
ubuntu壓縮及解壓檔案
1.壓縮zip # zip -r archive_name.zip directory_to_compress 2.tar只是打包並不壓縮,好處就是它只消耗非常少的CPU以及時間去打包檔案 # tar -cvf archive_name.tar directory_to_compress
Python使用urllib下載檔案以及使用zipfile解壓檔案
首先定義檔案下載路徑,檔名 import os from six.moves import urllib import zipfile DATA_URL = 'https://archive.ics.uci.edu/ml/machine-learning-databases/00240/UCI%
xz解壓和zip解壓
$xz -d ***.tar.xz $tar -xvf ***.tar 可以看到這個壓縮包也是打包後再壓縮,外面是xz壓縮方式,裡層是tar打包方式。
Unity3D打包 將釋出的exe檔案打包成一個Windows安裝檔案(自解壓檔案)
Unity打包Standalone時 會出現一個exe檔案和一個data資料夾 可是我們平常見過的軟體 基本沒有這種像這種結構的 一般都是一個安裝檔案,然後點選安裝,選擇路徑,生成快捷方式… 本篇部落格將介紹如何將Unity釋出的內容打包成一個安裝檔案 並具備選擇安裝路徑、生
linux用tar解壓檔案Cannot open: No such file or directory
在阿里雲上搭建大資料平臺,解壓 zookeeper-3.4.10.tar.gz時報錯如下: tar: zookeeper-3.4.10: Cannot mkdir: Permission denied tar: zookeeper-3.4.10/ivysettings.xml: Can
gzip: stdin: unexpected end of file Linux解壓檔案出錯
[[email protected] jdk1.8]# tar -zxvf jdk-8u161-linux-x64.tar.gz jdk1.8.0_161/ jdk1.8.0_161/javafx-src.zip gzip: stdin: unexpected e
Linux 解壓檔案詳解
Linux下的壓縮解壓縮命令詳解及例項 例項:壓縮伺服器上當前目錄的內容為xxx.zip檔案 zip -r xxx.zip ./* 解壓zip檔案到當前目錄 unzip filename.zip ============================ 另:有些伺
Mac連線Linux伺服器並上傳、解壓檔案
由於工作原因,要求在Linux伺服器沒網路的情況下部署專案——首先我要做的是將相關檔案上傳至伺服器。我在網上搜了很多相關資料,結合自身實際情況,整理出我所做的步驟,以供參考。 目的:Mac連線上Linux伺服器,並將檔案上傳至Linux伺服器
ubuntu之壓縮與解壓檔案
ubuntu之壓縮與解壓檔案 安裝壓縮工具 sudo apt-get install rar 安裝解壓工具 sudo apt-get install unrar .tar 解包: tar xvf xxx.tar 打包: tar cvf xxx.tar dirname
Android Zip解壓帶進度回撥
public interface IProgress { void onProgress(int progress); void onError(String msg); void onDone(); } private s
Huffman編碼實現壓縮、解壓檔案
Huffman編碼:根據詞頻構建Huffman樹,實現對文字的字首編碼。 1、統計文字中每個字元出現的次數,放入優先佇列中,構建一棵空的二叉樹; 2、取出頻率最小的兩個字元a、b,字元a、b的頻率分別作為此二叉樹的左右結點,左結點的編號為1,右結點的編號為0,其頻率之和(f
gunzip 和 unzip 解壓檔案到指定的目錄
1. gz檔案 這種檔案可以使用gzip、gunzip、zcat進行解壓: gzip -d file_name gunzip -d file_name zcat file_name 2. tar.gz、tgz檔案 這種壓縮檔案使用解壓命令和tar命令配合使用,