PHAssetResourceInputStream 0.0.6

PHAssetResourceInputStream 0.0.6

测试已测试
语言编程语言 SwiftSwift
许可证 MIT
发布最后发布2018年3月
SPM支持 SPM

Aleksandr Dvornikov维护。



  • 作者:
  • Aleksandr Dvornikov

描述

PHAssetResourceInputStream 是一个库,它为 Photos Framework 中的资源添加了输入流支持。它是基于 POSInputStreamLibrary 构建的,并在底层使用 有限阻塞队列 来反转 PHAssetResourceManager 的生产者-like API,使其更适合消费者使用。

示例

创建一个流

let inputStream = InputStream.inputStream(withAssetResource: assetResource)

设置偏移量

inputStream.setProperty(100, forKey: .fileCurrentOffsetKey)

此外,该库提供了一套数据结构,允许您以同步方式处理 PHAssetResource 的数据。

以下是从 PHAssetResource 获取大小的示例:

let dataProducer = PHAssetResourceDataProducer(assetResource: assetResource)
let dataGenerator = DataGeneratorFromDataProducer(dataProducer: dataProducer)

do {
    var size = 0
    while let data = try dataGenerator.nextChunk() {
        size += data.length
    }
    print(size)
} catch let error {
    print("Error occured: \(error)")
}

待办事项

  • [-] 添加示例项目

安装

PHAssetResourceInputStream 可通过 CocoaPods 获取。要安装,请在 Podfile 中指定它:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!

target '<Your Target Name>' do
    pod 'PHAssetResourceInputStream'
end

许可证

PHAssetResourceInputStream 在 MIT 许可下可用。有关更多信息,请参阅 LICENSE 文件。