github.com/keysonZZZ/kmg@v0.0.0-20151121023212-05317bfd7d39/kmgRpc/kmgRpcSwift/SwiftSource.go (about) 1 package kmgRpcSwift 2 3 func NSDataCompressionHead() string { 4 return ` 5 // 请将该文件放到根目录的项目名文件下 6 // NSData+Compression.h 7 // CocoaGit 8 // 9 // Created by Geoffrey Garside on 29/06/2008. 10 // Copyright 2008 ManicPanda.com. All rights reserved. 11 // 12 // Methods extracted from source given at 13 // http://www.cocoadev.com/index.pl?NSDataCategory 14 // 15 16 #import <Foundation/NSData.h> 17 18 /*! Adds compression and decompression messages to NSData. 19 * Methods extracted from source given at 20 * http://www.cocoadev.com/index.pl?NSDataCategory 21 */ 22 @interface NSData (Compression) 23 24 #pragma mark - 25 #pragma mark Zlib Compression routines 26 /*! Returns a data object containing a Zlib decompressed copy of the receivers contents. 27 * \returns A data object containing a Zlib decompressed copy of the receivers contents. 28 */ 29 - (NSData *) zlibInflate; 30 /*! Returns a data object containing a Zlib compressed copy of the receivers contents. 31 * \returns A data object containing a Zlib compressed copy of the receivers contents. 32 */ 33 - (NSData *) zlibDeflate; 34 35 #pragma mark - 36 #pragma mark Gzip Compression routines 37 /*! Returns a data object containing a Gzip decompressed copy of the receivers contents. 38 * \returns A data object containing a Gzip decompressed copy of the receivers contents. 39 */ 40 - (NSData *) gzipInflate; 41 /*! Returns a data object containing a Gzip compressed copy of the receivers contents. 42 * \returns A data object containing a Gzip compressed copy of the receivers contents. 43 */ 44 - (NSData *) gzipDeflate; 45 46 @end 47 ` 48 } 49 func NSDataCompressionMethod() string { 50 return ` 51 // 请将该文件放到根目录的项目名文件下 52 // NSData+Compression.m 53 // CocoaGit 54 // 55 // Created by Geoffrey Garside on 29/06/2008. 56 // Copyright 2008 ManicPanda.com. All rights reserved. 57 // 58 // Methods extracted from source given at 59 // http://www.cocoadev.com/index.pl?NSDataCategory 60 // 61 62 #import "NSData+Compression.h" 63 #include <zlib.h> 64 65 @implementation NSData (Compression) 66 67 #pragma mark - 68 #pragma mark Zlib Compression routines 69 - (NSData *) zlibInflate 70 { 71 if ([self length] == 0) return self; 72 73 unsigned full_length = [self length]; 74 unsigned half_length = [self length] / 2; 75 76 NSMutableData *decompressed = [NSMutableData dataWithLength: full_length + half_length]; 77 BOOL done = NO; 78 int status; 79 80 z_stream strm; 81 strm.next_in = (Bytef *)[self bytes]; 82 strm.avail_in = [self length]; 83 strm.total_out = 0; 84 strm.zalloc = Z_NULL; 85 strm.zfree = Z_NULL; 86 87 if (inflateInit (&strm) != Z_OK) return nil; 88 89 while (!done) 90 { 91 // Make sure we have enough room and reset the lengths. 92 if (strm.total_out >= [decompressed length]) 93 [decompressed increaseLengthBy: half_length]; 94 strm.next_out = [decompressed mutableBytes] + strm.total_out; 95 strm.avail_out = [decompressed length] - strm.total_out; 96 97 // Inflate another chunk. 98 status = inflate (&strm, Z_SYNC_FLUSH); 99 if (status == Z_STREAM_END) done = YES; 100 else if (status != Z_OK) break; 101 } 102 if (inflateEnd (&strm) != Z_OK) return nil; 103 104 // Set real length. 105 if (done) 106 { 107 [decompressed setLength: strm.total_out]; 108 return [NSData dataWithData: decompressed]; 109 } 110 else return nil; 111 } 112 - (NSData *) zlibDeflate 113 { 114 if ([self length] == 0) return self; 115 116 z_stream strm; 117 118 strm.zalloc = Z_NULL; 119 strm.zfree = Z_NULL; 120 strm.opaque = Z_NULL; 121 strm.total_out = 0; 122 strm.next_in=(Bytef *)[self bytes]; 123 strm.avail_in = [self length]; 124 125 // Compresssion Levels: 126 // Z_NO_COMPRESSION 127 // Z_BEST_SPEED 128 // Z_BEST_COMPRESSION 129 // Z_DEFAULT_COMPRESSION 130 131 if (deflateInit(&strm, Z_DEFAULT_COMPRESSION) != Z_OK) return nil; 132 133 // 16K chuncks for expansion 134 NSMutableData *compressed = [NSMutableData dataWithLength:16384]; 135 136 do { 137 138 if (strm.total_out >= [compressed length]) 139 [compressed increaseLengthBy: 16384]; 140 141 strm.next_out = [compressed mutableBytes] + strm.total_out; 142 strm.avail_out = [compressed length] - strm.total_out; 143 144 deflate(&strm, Z_FINISH); 145 146 } while (strm.avail_out == 0); 147 148 deflateEnd(&strm); 149 150 [compressed setLength: strm.total_out]; 151 return [NSData dataWithData: compressed]; 152 } 153 154 #pragma mark - 155 #pragma mark Gzip Compression routines 156 - (NSData *) gzipInflate 157 { 158 if ([self length] == 0) return self; 159 160 unsigned full_length = [self length]; 161 unsigned half_length = [self length] / 2; 162 163 NSMutableData *decompressed = [NSMutableData dataWithLength: full_length + half_length]; 164 BOOL done = NO; 165 int status; 166 167 z_stream strm; 168 strm.next_in = (Bytef *)[self bytes]; 169 strm.avail_in = [self length]; 170 strm.total_out = 0; 171 strm.zalloc = Z_NULL; 172 strm.zfree = Z_NULL; 173 174 if (inflateInit2(&strm, (15+32)) != Z_OK) return nil; 175 while (!done) 176 { 177 // Make sure we have enough room and reset the lengths. 178 if (strm.total_out >= [decompressed length]) 179 [decompressed increaseLengthBy: half_length]; 180 strm.next_out = [decompressed mutableBytes] + strm.total_out; 181 strm.avail_out = [decompressed length] - strm.total_out; 182 183 // Inflate another chunk. 184 status = inflate (&strm, Z_SYNC_FLUSH); 185 if (status == Z_STREAM_END) done = YES; 186 else if (status != Z_OK) break; 187 } 188 if (inflateEnd (&strm) != Z_OK) return nil; 189 190 // Set real length. 191 if (done) 192 { 193 [decompressed setLength: strm.total_out]; 194 return [NSData dataWithData: decompressed]; 195 } 196 else return nil; 197 } 198 - (NSData *) gzipDeflate 199 { 200 if ([self length] == 0) return self; 201 202 z_stream strm; 203 204 strm.zalloc = Z_NULL; 205 strm.zfree = Z_NULL; 206 strm.opaque = Z_NULL; 207 strm.total_out = 0; 208 strm.next_in=(Bytef *)[self bytes]; 209 strm.avail_in = [self length]; 210 211 // Compresssion Levels: 212 // Z_NO_COMPRESSION 213 // Z_BEST_SPEED 214 // Z_BEST_COMPRESSION 215 // Z_DEFAULT_COMPRESSION 216 217 if (deflateInit2(&strm, Z_DEFAULT_COMPRESSION, Z_DEFLATED, 218 (15+16), 8, Z_DEFAULT_STRATEGY) != Z_OK) return nil; 219 220 // 16K chunks for expansion 221 NSMutableData *compressed = [NSMutableData dataWithLength:16384]; 222 223 do { 224 225 if (strm.total_out >= [compressed length]) 226 [compressed increaseLengthBy: 16384]; 227 228 strm.next_out = [compressed mutableBytes] + strm.total_out; 229 strm.avail_out = [compressed length] - strm.total_out; 230 231 deflate(&strm, Z_FINISH); 232 233 } while (strm.avail_out == 0); 234 235 deflateEnd(&strm); 236 237 [compressed setLength: strm.total_out]; 238 return [NSData dataWithData:compressed]; 239 } 240 241 @end 242 ` 243 } 244 func InfoList() string { 245 return ` 246 <?xml version="1.0" encoding="UTF-8"?> 247 <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> 248 <plist version="1.0"> 249 <dict> 250 <key>CFBundleName</key> 251 <string>$(PRODUCT_NAME)</string> 252 <key>CFBundleIdentifier</key> 253 <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string> 254 <key>CFBundleInfoDictionaryVersion</key> 255 <string>6.0</string> 256 <key>UIMainStoryboardFile</key> 257 <string>Main</string> 258 <key>CFBundleVersion</key> 259 <string>1</string> 260 <key>UILaunchStoryboardName</key> 261 <string>LaunchScreen</string> 262 <key>CFBundleExecutable</key> 263 <string>$(EXECUTABLE_NAME)</string> 264 <key>LSRequiresIPhoneOS</key> 265 <true/> 266 <key>UIRequiredDeviceCapabilities</key> 267 <array> 268 <string>armv7</string> 269 </array> 270 <key>UISupportedInterfaceOrientations</key> 271 <array> 272 <string>UIInterfaceOrientationPortrait</string> 273 <string>UIInterfaceOrientationLandscapeLeft</string> 274 <string>UIInterfaceOrientationLandscapeRight</string> 275 </array> 276 <key>NSAppTransportSecurity</key> 277 <dict> 278 <key>NSAllowsArbitraryLoads</key> 279 <true/> 280 </dict> 281 <key>CFBundleSignature</key> 282 <string>????</string> 283 <key>CFBundlePackageType</key> 284 <string>APPL</string> 285 <key>CFBundleDevelopmentRegion</key> 286 <string>en</string> 287 <key>UISupportedInterfaceOrientations~ipad</key> 288 <array> 289 <string>UIInterfaceOrientationPortrait</string> 290 <string>UIInterfaceOrientationPortraitUpsideDown</string> 291 <string>UIInterfaceOrientationLandscapeLeft</string> 292 <string>UIInterfaceOrientationLandscapeRight</string> 293 </array> 294 <key>CFBundleShortVersionString</key> 295 <string>1.0</string> 296 </dict> 297 </plist> 298 ` 299 } 300 func Podfile(projectName string) string { 301 return ` 302 #请将该文件放到ios项目根目录,并执行pod install,之后通过xworkspace打开 303 target '` + projectName + 304 `' do 305 source 'https://github.com/CocoaPods/Specs.git' 306 #platform :ios, '8.0' 307 use_frameworks! 308 pod 'CryptoSwift', :git => "https://github.com/zhengrf225/CryptoSwift.git", :branch => "master" 309 pod 'Alamofire', '~> 2.0' 310 pod 'SwiftyJSON', :git => 'https://github.com/SwiftyJSON/SwiftyJSON.git' 311 end 312 ` 313 }