- decompressUsingAlgorithm:error:
NSDataCompressionAlgorithm
Availability 有効性
Technology
- (BOOL)compressUsingAlgorithm:(NSDataCompressionAlgorithm
)algorithm
error:(NSError
* _Nullable *)error;
algorithm
The algorithm to use to compress the data. For a list of available algorithms, see NSData
.
データを圧縮するために使用するアルゴリズム。利用可能なアルゴリズムの一覧として、NSData
を見てください。
error
Use this method to compress in-memory data when you want to reduce memory usage and can afford the time to compress and decompress the data. If your data object is already in a compressed format, such as media formats like JPEG images or AAC audio, compress
may provide minimal or no benefit.
このメソッドを使用して、インメモリデータを圧縮してください、あなたがメモリ使用を減らしたいそしてデータを圧縮および解凍する時間がさける場合に。あなたのデータオブジェクトが既に圧縮された形式であるならば、たとえばJPEG画像やAACオーディオのようなメディア形式など、compress
はごくわずかまたは少しの利益も提供しないかもしれません。
The following example shows how to compress data from a string and prints the sizes of the data instances to illustrate the amount of compression: 以下の例は、どのようにある文字列からのデータを圧縮するかを示します、そしてデータインスタンスのサイズを圧縮量を明らかにするために出力します:
var string = "NSData and its mutable subclass NSMutableData provide data objects, or object-oriented wrappers for byte buffers. Data objects let simple allocated buffers (that is, data with no embedded pointers) take on the behavior of Foundation objects."
let data = NSMutableData(data: Data(string.utf8))
print ("original data size: \(data.length)")
do {
try data.compress(using: .zlib)
print("zlib compressed size: \(data.length)")
} catch {
print ("Compression error: \(error)")
}
// Prints:
// original data size: 241
// zlib compressed size: 158
- decompressUsingAlgorithm:error:
NSDataCompressionAlgorithm