Explorar o código

Add method to get deflated data from compressed data.

Requires linking to libz
Ryan Olson %!s(int64=11) %!d(string=hai) anos
pai
achega
2b3677e503

+ 1 - 0
Classes/Utility/FLEXUtility.h

@@ -35,5 +35,6 @@
 + (NSString *)statusCodeStringFromURLResponse:(NSURLResponse *)response;
 + (NSDictionary *)dictionaryFromQuery:(NSString *)query;
 + (NSString *)prettyJSONStringFromData:(NSData *)data;
++ (NSData *)deflatedDataFromCompressedData:(NSData *)compressedData;
 
 @end

+ 36 - 0
Classes/Utility/FLEXUtility.m

@@ -9,6 +9,7 @@
 #import "FLEXUtility.h"
 #import "FLEXResources.h"
 #import <ImageIO/ImageIO.h>
+#import <zlib.h>
 
 @implementation FLEXUtility
 
@@ -270,4 +271,39 @@
     return prettyString;
 }
 
++ (NSData *)deflatedDataFromCompressedData:(NSData *)compressedData
+{
+    NSData *deflatedData = nil;
+    NSUInteger compressedDataLength = [compressedData length];
+    if (compressedDataLength > 0) {
+        z_stream stream;
+        stream.zalloc = Z_NULL;
+        stream.zfree = Z_NULL;
+        stream.avail_in = (uInt)compressedDataLength;
+        stream.next_in = (void *)[compressedData bytes];
+        stream.total_out = 0;
+        stream.avail_out = 0;
+
+        NSMutableData *mutableData = [NSMutableData dataWithLength:compressedDataLength * 1.5];
+        if (inflateInit2(&stream, 15 + 32) == Z_OK) {
+            int status = Z_OK;
+            while (status == Z_OK) {
+                if (stream.total_out >= [mutableData length]) {
+                    mutableData.length += compressedDataLength / 2;
+                }
+                stream.next_out = (uint8_t *)[mutableData mutableBytes] + stream.total_out;
+                stream.avail_out = (uInt)([mutableData length] - stream.total_out);
+                status = inflate(&stream, Z_SYNC_FLUSH);
+            }
+            if (inflateEnd(&stream) == Z_OK) {
+                if (status == Z_STREAM_END) {
+                    mutableData.length = stream.total_out;
+                    deflatedData = [mutableData copy];
+                }
+            }
+        }
+    }
+    return deflatedData;
+}
+
 @end

+ 4 - 0
Example/UICatalog.xcodeproj/project.pbxproj

@@ -104,6 +104,7 @@
 		946C6ECF1A7599C4006545C2 /* FLEXSystemLogMessage.m in Sources */ = {isa = PBXBuildFile; fileRef = 946C6ECE1A7599C4006545C2 /* FLEXSystemLogMessage.m */; };
 		94C681F31A3E941800E1936D /* FLEXLayerExplorerViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 94C681F21A3E941800E1936D /* FLEXLayerExplorerViewController.m */; };
 		94CB48391A8EC6000054A905 /* FLEXMultilineTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 94CB48381A8EC6000054A905 /* FLEXMultilineTableViewCell.m */; };
+		94CB4D431A97183E0054A905 /* libz.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 94CB4D421A97183E0054A905 /* libz.dylib */; };
 		D03647D919847248007D2A1B /* FLEXGlobalsTableViewControllerEntry.m in Sources */ = {isa = PBXBuildFile; fileRef = D03647D819847248007D2A1B /* FLEXGlobalsTableViewControllerEntry.m */; };
 /* End PBXBuildFile section */
 
@@ -295,6 +296,7 @@
 		94C681F21A3E941800E1936D /* FLEXLayerExplorerViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FLEXLayerExplorerViewController.m; sourceTree = "<group>"; };
 		94CB48371A8EC6000054A905 /* FLEXMultilineTableViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FLEXMultilineTableViewCell.h; sourceTree = "<group>"; };
 		94CB48381A8EC6000054A905 /* FLEXMultilineTableViewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FLEXMultilineTableViewCell.m; sourceTree = "<group>"; };
+		94CB4D421A97183E0054A905 /* libz.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libz.dylib; path = usr/lib/libz.dylib; sourceTree = SDKROOT; };
 		D03647D51984720F007D2A1B /* FLEXManager+Private.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "FLEXManager+Private.h"; sourceTree = "<group>"; };
 		D03647D719847248007D2A1B /* FLEXGlobalsTableViewControllerEntry.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FLEXGlobalsTableViewControllerEntry.h; sourceTree = "<group>"; };
 		D03647D819847248007D2A1B /* FLEXGlobalsTableViewControllerEntry.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FLEXGlobalsTableViewControllerEntry.m; sourceTree = "<group>"; };
@@ -305,6 +307,7 @@
 			isa = PBXFrameworksBuildPhase;
 			buildActionMask = 2147483647;
 			files = (
+				94CB4D431A97183E0054A905 /* libz.dylib in Frameworks */,
 				5356824018F3656900BAAD62 /* CoreGraphics.framework in Frameworks */,
 				5356824218F3656900BAAD62 /* UIKit.framework in Frameworks */,
 				5356823E18F3656900BAAD62 /* Foundation.framework in Frameworks */,
@@ -336,6 +339,7 @@
 		5356823C18F3656900BAAD62 /* Frameworks */ = {
 			isa = PBXGroup;
 			children = (
+				94CB4D421A97183E0054A905 /* libz.dylib */,
 				5356823D18F3656900BAAD62 /* Foundation.framework */,
 				5356823F18F3656900BAAD62 /* CoreGraphics.framework */,
 				5356824118F3656900BAAD62 /* UIKit.framework */,

+ 1 - 0
FLEX.podspec

@@ -31,5 +31,6 @@ Pod::Spec.new do |spec|
   spec.source           = { :git => "https://github.com/Flipboard/FLEX.git", :tag => "#{spec.version}" }
   spec.source_files     = "Classes/**/*.{h,m}"
   spec.frameworks       = "CoreGraphics"
+  spec.libraries        = "z"
   spec.requires_arc     = true
 end