我需要在 RubyMotion 中下载并解压缩文件。我尝试寻找示例,但找不到任何此过程。
我有一个变量(@file),它是请求中的所有数据。我需要将该数据写入文件,然后解压缩,保留未压缩的数据并删除 tmp 压缩文件。
这是我到目前为止所拥有的:
class LoadResourcesViewController < UIViewController
def viewDidAppear(animated)
@loading_bar = retrieve_subview_with_tag(self, 1)
req=NSURLRequest.requestWithURL(NSURL.URLWithString("#{someurl}"))
@connection = NSURLConnection.alloc.initWithRequest req, delegate: self, startImmediately: true
end
def connection(connection, didFailWithError:error)
p error
end
def connection(connection, didReceiveResponse:response)
@file = NSMutableData.data
@response = response
@download_size = response.expectedContentLength
end
def connection(connection, didReceiveData:data)
@file.appendData data
@loading_bar.setProgress(@file.length.to_f/@download_size.to_f)
end
def connectionDidFinishLoading(connection)
#create tmp file
#uncompress .tar, .tar.gz or .zip
#presist uncompresssed files and delete original tmp file
puts @file.inspect
@connection.release
solutionStoryboard = UIStoryboard.storyboardWithName("Master", bundle:nil)
myVC = solutionStoryboard.instantiateViewControllerWithIdentifier("Main3")
self.presentModalViewController(myVC, animated:true)
end
end
任何帮助或示例都会很棒!