一:MiMEType:一般可以再百度上搜索到相应文件的MiMEType,或是利用c语言的api去获取文件的MiMEType

//对该文件发送一个异步请求,拿到文件的MIMEType

- (void)MIMEType

{

//    NSString *file = @"file:///Users/文顶顶/Desktop/test.png";

[NSURLConnection sendAsynchronousRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:@"/Users/文顶顶/Desktop/test.png"]] queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse * __nullable response, NSData * __nullable data, NSError * __nullable connectionError) {

//       response.MIMEType

NSLog(@"%@",response.MIMEType);

}];

}

```

(2)通过UTTypeCopyPreferredTagWithClass方法

```objc

//注意:需要依赖于框架MobileCoreServices

- (NSString *)mimeTypeForFileAtPath:(NSString *)path

{

if (![[[NSFileManager alloc] init] fileExistsAtPath:path]) {

return nil;

}

CFStringRef UTI = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, (__bridge CFStringRef)[path pathExtension], NULL);

CFStringRef MIMEType = UTTypeCopyPreferredTagWithClass (UTI, kUTTagClassMIMEType);

CFRelease(UTI);

if (!MIMEType) {

return @"application/octet-stream";

}

return (__bridge NSString *)(MIMEType);

}

```

二:多线程文件下载思路:将下载文件分成若干段,每段任务创建一条线程,多个任务并发执行下载文件的操作,不能利用输出流进行文件二进制数据data的拼接,否则会出现数据错乱。利用文件句柄,在代理方法中,接受到数据后,判断是哪条线程,再根据线程的不同,将文件句柄的位置偏移到seekoffset,偏移到相应线程的下载的地方

三:文件的压缩和解压缩

  1. #import "ViewController.h"
  2. #import "SSZipArchive.h"
  3.  
  4. @interface ViewController ()
  5.  
  6. @end
  7.  
  8. @implementation ViewController
  9. -(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
  10. {
  11. [self unzip];
  12. }
  13.  
  14. -(void)zip
  15. {
  16. NSArray *arrayM = @[
  17. @"/Users/xiaomage/Desktop/Snip20160226_2.png",
  18. @"/Users/xiaomage/Desktop/Snip20160226_6.png"
  19. ];
  20. /*
  21. 第一个参数:压缩文件的存放位置
  22. 第二个参数:要压缩哪些文件(路径)
  23. */
  24. //[SSZipArchive createZipFileAtPath:@"/Users/xiaomage/Desktop/Test.zip" withFilesAtPaths:arrayM];
  25. [SSZipArchive createZipFileAtPath:@"/Users/xiaomage/Desktop/Test.zip" withFilesAtPaths:arrayM withPassword:@""];
  26. }
  27.  
  28. -(void)zip2
  29. {
  30. /*
  31. 第一个参数:压缩文件存放位置
  32. 第二个参数:要压缩的文件夹(目录)
  33. */
  34. [SSZipArchive createZipFileAtPath:@"/Users/xiaomage/Desktop/demo.zip" withContentsOfDirectory:@"/Users/xiaomage/Desktop/demo"];
  35. }
  36.  
  37. -(void)unzip
  38. {
  39. /*
  40. 第一个参数:要解压的文件在哪里
  41. 第二个参数:文件应该解压到什么地方
  42. */
  43. //[SSZipArchive unzipFileAtPath:@"/Users/xiaomage/Desktop/demo.zip" toDestination:@"/Users/xiaomage/Desktop/xx"];
  44.  
  45. [SSZipArchive unzipFileAtPath:@"/Users/xiaomage/Desktop/demo.zip" toDestination:@"/Users/xiaomage/Desktop/xx" progressHandler:^(NSString *entry, unz_file_info zipInfo, long entryNumber, long total) {
  46. NSLog(@"%zd---%zd",entryNumber,total);
  47.  
  48. } completionHandler:^(NSString *path, BOOL succeeded, NSError *error) {
  49.  
  50. NSLog(@"%@",path);
  51. }];
  52. }
  53.  
  54. @end

ios开发网络学习五:MiMEType ,多线程下载文件思路,文件的压缩和解压缩的更多相关文章

  1. ios开发网络学习五:输出流以及文件上传

    一:输出流 #import "ViewController.h" @interface ViewController ()<NSURLConnectionDataDelega ...

  2. ios开发网络学习九:NSURLSessionDownloadTask实现大文件下载

    一:NSURLSessionDownloadTask:实现文件下载:无法监听进度 #import "ViewController.h" @interface ViewControl ...

  3. ios开发网络学习十一:NSURLSessionDataTask离线断点下载(断点续传)

    #import "ViewController.h" #define FileName @"121212.mp4" @interface ViewControl ...

  4. ios开发网络学习四:NSURLConnection大文件断点下载

    #import "ViewController.h" @interface ViewController ()<NSURLConnectionDataDelegate> ...

  5. ios开发网络学习AFN框架的使用一:get和post请求

    #import "ViewController.h" #import "AFNetworking.h" @interface ViewController () ...

  6. ios开发网络学习十二:NSURLSession实现文件上传

    #import "ViewController.h" // ----WebKitFormBoundaryvMI3CAV0sGUtL8tr #define Kboundary @&q ...

  7. ios开发runtime学习五:KVC以及KVO,利用runtime实现字典转模型

    一:KVC和KVO的学习 #import "StatusItem.h" /* 1:总结:KVC赋值:1:setValuesForKeysWithDictionary实现原理:遍历字 ...

  8. ios开发网络学习三:NSURLConnection小文件大文件下载

    一:小文件下载 #import "ViewController.h" @interface ViewController ()<NSURLConnectionDataDele ...

  9. ios开发网络学习:一:NSURLConnection发送GET,POST请求

    #import "ViewController.h" @interface ViewController ()<NSURLConnectionDataDelegate> ...

随机推荐

  1. jQuery Easy UI Panel(面板)组件

    panel(面板)组件,跟前面的组件使用方法差点儿都差点儿相同,也是从设置一些面板属性.操作面板触发的事件.我们可针对面板对象的操作方法这三个点去学习. 后面有一些组件要依赖于这个组件. 另一点跟前面 ...

  2. 前端项目中常用es6知识总结 -- Async、Await让异步美如画

    项目开发中一些常用的es6知识,主要是为以后分享小程序开发.node+koa项目开发以及vueSSR(vue服务端渲染)做个前置铺垫. 项目开发常用es6介绍 1.块级作用域 let const 2. ...

  3. Mybatis批量插入,是否能够返回id列表

    第1次代码 void batchAdd(List<Photo> list); <insert id="batchAdd" parameterType=" ...

  4. SpringCloud核心教程 | 第三篇:服务注册与发现 Eureka篇

    Spring Cloud简介 Spring Cloud是一个基于Spring Boot实现的云应用开发工具,它为基于JVM的云应用开发中涉及的配置管理.服务发现.断路器.智能路由.微代理.控制总线.全 ...

  5. shell实例浅谈之三产生随机数七种方法

    一.问题 Shell下有时须要使用随机数,在此总结产生随机数的方法.计算机产生的的仅仅是"伪随机数".不会产生绝对的随机数(是一种理想随机数).伪随机数在大量重现时也并不一定保持唯 ...

  6. theme-windowAnimationStyle 动画四个方法的意义

    首先看代码 <style name="Animation.Activity"> <!--A打开B,B的出现动画--> <item name=" ...

  7. sass工具、相关插件

    http://koala-app.com/index-zh.html 下载koala 把css文件夹(包含.scss后缀的文件)整个拖进去: 然后在sublime打开.scss文件编译,自动生成css ...

  8. 前端面试题(webpack)

    (前端面试题大全,持续更新) webpack3升级到4为什么会提升速度? webpack优化有哪些? webpack的css-loader原理讲一下 webpack压缩js css的方法

  9. vc 常用语句

    1) CMainFrame* pmainframe=(CMainFrame*)AfxGetMainWnd();CChildFrame *m_finderframe=(CChildFrame*)pmai ...

  10. sass和less,优秀的前端样式预处理器

    身为切图界的一员,或者说在前端界打滚了一段日子的你.会慢慢地发现.如今的css编写已经不能满足自己的效率. 假设有更强大的框架,让你的css更灵活和更easy复用和维护,那该多好啊.非常明显,这个早已 ...