How used Brotli Decoder in Objective-C #447

Open
opened 2026-01-29 20:44:02 +00:00 by claunia · 0 comments
Owner

Originally created by @iHTCboy on GitHub (Feb 23, 2023).

ChatGPT:

- (NSData *)decodeBrotliData:(NSData *)compressedData {
    size_t decompressedLength = BrotliDecoderDecompressedSize([compressedData length], [compressedData bytes]);
    if (decompressedLength == BROTLI_DECODER_RESULT_ERROR) {
        NSLog(@"Failed to decompress Brotli encoding data");
        return nil;
    }

    NSMutableData *decompressedData = [NSMutableData dataWithLength:decompressedLength];
    size_t outSize = [decompressedData length];
    const uint8_t *compressedBytes = [compressedData bytes];
    uint8_t *outBytes = [decompressedData mutableBytes];

    if (BrotliDecoderDecompress(0, compressedBytes, [compressedData length], &outSize, outBytes) != BROTLI_DECODER_RESULT_SUCCESS) {
        NSLog(@"Failed to decompress Brotli encoding data");
        return nil;
    }

    return decompressedData;
}

BrotliDecoderDecompressedSize Can't find

Originally created by @iHTCboy on GitHub (Feb 23, 2023). ChatGPT: ``` - (NSData *)decodeBrotliData:(NSData *)compressedData { size_t decompressedLength = BrotliDecoderDecompressedSize([compressedData length], [compressedData bytes]); if (decompressedLength == BROTLI_DECODER_RESULT_ERROR) { NSLog(@"Failed to decompress Brotli encoding data"); return nil; } NSMutableData *decompressedData = [NSMutableData dataWithLength:decompressedLength]; size_t outSize = [decompressedData length]; const uint8_t *compressedBytes = [compressedData bytes]; uint8_t *outBytes = [decompressedData mutableBytes]; if (BrotliDecoderDecompress(0, compressedBytes, [compressedData length], &outSize, outBytes) != BROTLI_DECODER_RESULT_SUCCESS) { NSLog(@"Failed to decompress Brotli encoding data"); return nil; } return decompressedData; } ``` `BrotliDecoderDecompressedSize` Can't find
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/brotli#447