Revision: 9758 http://sourceforge.net/p/skim-app/code/9758 Author: hofman Date: 2018-04-11 14:09:54 +0000 (Wed, 11 Apr 2018) Log Message: ----------- Macro for zip buffer size, use same size for compress and decompress
Modified Paths: -------------- trunk/SkimNotes/SKNExtendedAttributeManager.m Modified: trunk/SkimNotes/SKNExtendedAttributeManager.m =================================================================== --- trunk/SkimNotes/SKNExtendedAttributeManager.m 2018-04-11 13:58:03 UTC (rev 9757) +++ trunk/SkimNotes/SKNExtendedAttributeManager.m 2018-04-11 14:09:54 UTC (rev 9758) @@ -564,6 +564,8 @@ // implementation modified after http://www.cocoadev.com/index.pl?NSDataPlusBzip (removed exceptions) // +#define BZIP_BUFFER_SIZE 16 * 1024 + - (NSData *)bzipData:(NSData *)data; { int compression = 5; @@ -572,27 +574,23 @@ stream.next_in = (char *)[data bytes]; stream.avail_in = (unsigned int)[data length]; - const unsigned int buffer_size = 1000000; - NSMutableData *buffer = [[NSMutableData alloc] initWithLength:buffer_size]; + NSMutableData *buffer = [[NSMutableData alloc] initWithLength:BZIP_BUFFER_SIZE]; stream.next_out = [buffer mutableBytes]; - stream.avail_out = buffer_size; + stream.avail_out = BZIP_BUFFER_SIZE; NSMutableData *compressed = [NSMutableData dataWithCapacity:[data length]]; BZ2_bzCompressInit(&stream, compression, 0, 0); BOOL hadError = NO; - NSInteger hangCount = 0; - const NSInteger maxHangCount = 100; do { bzret = BZ2_bzCompress(&stream, (stream.avail_in) ? BZ_RUN : BZ_FINISH); - if ((bzret != BZ_RUN_OK && bzret != BZ_FINISH_OK && bzret != BZ_STREAM_END) || - (buffer_size == stream.avail_out && ++hangCount > maxHangCount)) { + if (bzret != BZ_RUN_OK && bzret != BZ_FINISH_OK && bzret != BZ_STREAM_END) { hadError = YES; compressed = nil; } else { - [compressed appendBytes:[buffer bytes] length:(buffer_size - stream.avail_out)]; + [compressed appendBytes:[buffer bytes] length:(BZIP_BUFFER_SIZE - stream.avail_out)]; stream.next_out = [buffer mutableBytes]; - stream.avail_out = buffer_size; + stream.avail_out = BZIP_BUFFER_SIZE; } } while(bzret != BZ_STREAM_END && NO == hadError); @@ -609,10 +607,9 @@ stream.next_in = (char *)[data bytes]; stream.avail_in = (unsigned int)[data length]; - const unsigned int buffer_size = 10000; - NSMutableData *buffer = [[NSMutableData alloc] initWithLength:buffer_size]; + NSMutableData *buffer = [[NSMutableData alloc] initWithLength:BZIP_BUFFER_SIZE]; stream.next_out = [buffer mutableBytes]; - stream.avail_out = buffer_size; + stream.avail_out = BZIP_BUFFER_SIZE; NSMutableData *decompressed = [NSMutableData dataWithCapacity:[data length]]; @@ -623,13 +620,13 @@ do { bzret = BZ2_bzDecompress(&stream); if ((bzret != BZ_OK && bzret != BZ_STREAM_END) || - (buffer_size == stream.avail_out && ++hangCount > maxHangCount)) { + (BZIP_BUFFER_SIZE == stream.avail_out && ++hangCount > maxHangCount)) { hadError = YES; decompressed = nil; } else { - [decompressed appendBytes:[buffer bytes] length:(buffer_size - stream.avail_out)]; + [decompressed appendBytes:[buffer bytes] length:(BZIP_BUFFER_SIZE - stream.avail_out)]; stream.next_out = [buffer mutableBytes]; - stream.avail_out = buffer_size; + stream.avail_out = BZIP_BUFFER_SIZE; } } while(bzret != BZ_STREAM_END && NO == hadError); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot _______________________________________________ Skim-app-commit mailing list Skim-app-commit@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/skim-app-commit