├── .gitignore
├── .swift-version
├── .travis.yml
├── AppledocSettings.plist
├── CHANGELOG.md
├── Extra
├── NOZXAppleCompressionCoder.h
├── NOZXAppleCompressionCoder.m
├── NOZXBrotliCompressionCoder.h
├── NOZXBrotliCompressionCoder.m
├── NOZXZStandardCompressionCoder.h
├── NOZXZStandardCompressionCoder.m
├── brotli
│ ├── common
│ │ ├── constants.c
│ │ ├── constants.h
│ │ ├── context.c
│ │ ├── context.h
│ │ ├── dictionary.bin
│ │ ├── dictionary.bin.br
│ │ ├── dictionary.c
│ │ ├── dictionary.h
│ │ ├── platform.c
│ │ ├── platform.h
│ │ ├── transform.c
│ │ ├── transform.h
│ │ └── version.h
│ ├── dec
│ │ ├── bit_reader.c
│ │ ├── bit_reader.h
│ │ ├── decode.c
│ │ ├── huffman.c
│ │ ├── huffman.h
│ │ ├── prefix.h
│ │ ├── state.c
│ │ └── state.h
│ ├── enc
│ │ ├── backward_references.c
│ │ ├── backward_references.h
│ │ ├── backward_references_hq.c
│ │ ├── backward_references_hq.h
│ │ ├── backward_references_inc.h
│ │ ├── bit_cost.c
│ │ ├── bit_cost.h
│ │ ├── bit_cost_inc.h
│ │ ├── block_encoder_inc.h
│ │ ├── block_splitter.c
│ │ ├── block_splitter.h
│ │ ├── block_splitter_inc.h
│ │ ├── brotli_bit_stream.c
│ │ ├── brotli_bit_stream.h
│ │ ├── cluster.c
│ │ ├── cluster.h
│ │ ├── cluster_inc.h
│ │ ├── command.c
│ │ ├── command.h
│ │ ├── compress_fragment.c
│ │ ├── compress_fragment.h
│ │ ├── compress_fragment_two_pass.c
│ │ ├── compress_fragment_two_pass.h
│ │ ├── dictionary_hash.c
│ │ ├── dictionary_hash.h
│ │ ├── encode.c
│ │ ├── encoder_dict.c
│ │ ├── encoder_dict.h
│ │ ├── entropy_encode.c
│ │ ├── entropy_encode.h
│ │ ├── entropy_encode_static.h
│ │ ├── fast_log.c
│ │ ├── fast_log.h
│ │ ├── find_match_length.h
│ │ ├── hash.h
│ │ ├── hash_composite_inc.h
│ │ ├── hash_forgetful_chain_inc.h
│ │ ├── hash_longest_match64_inc.h
│ │ ├── hash_longest_match_inc.h
│ │ ├── hash_longest_match_quickly_inc.h
│ │ ├── hash_rolling_inc.h
│ │ ├── hash_to_binary_tree_inc.h
│ │ ├── histogram.c
│ │ ├── histogram.h
│ │ ├── histogram_inc.h
│ │ ├── literal_cost.c
│ │ ├── literal_cost.h
│ │ ├── memory.c
│ │ ├── memory.h
│ │ ├── metablock.c
│ │ ├── metablock.h
│ │ ├── metablock_inc.h
│ │ ├── params.h
│ │ ├── prefix.h
│ │ ├── quality.h
│ │ ├── ringbuffer.h
│ │ ├── static_dict.c
│ │ ├── static_dict.h
│ │ ├── static_dict_lut.h
│ │ ├── utf8_util.c
│ │ ├── utf8_util.h
│ │ └── write_bits.h
│ └── include
│ │ └── brotli
│ │ ├── decode.h
│ │ ├── encode.h
│ │ ├── port.h
│ │ └── types.h
└── zstd
│ ├── common
│ ├── bitstream.h
│ ├── compiler.h
│ ├── cpu.h
│ ├── debug.c
│ ├── debug.h
│ ├── entropy_common.c
│ ├── error_private.c
│ ├── error_private.h
│ ├── fse.h
│ ├── fse_decompress.c
│ ├── huf.h
│ ├── mem.h
│ ├── pool.c
│ ├── pool.h
│ ├── threading.c
│ ├── threading.h
│ ├── xxhash.c
│ ├── xxhash.h
│ ├── zstd_common.c
│ ├── zstd_deps.h
│ ├── zstd_internal.h
│ └── zstd_trace.h
│ ├── compress
│ ├── fse_compress.c
│ ├── hist.c
│ ├── hist.h
│ ├── huf_compress.c
│ ├── zstd_compress.c
│ ├── zstd_compress_internal.h
│ ├── zstd_compress_literals.c
│ ├── zstd_compress_literals.h
│ ├── zstd_compress_sequences.c
│ ├── zstd_compress_sequences.h
│ ├── zstd_compress_superblock.c
│ ├── zstd_compress_superblock.h
│ ├── zstd_cwksp.h
│ ├── zstd_double_fast.c
│ ├── zstd_double_fast.h
│ ├── zstd_fast.c
│ ├── zstd_fast.h
│ ├── zstd_lazy.c
│ ├── zstd_lazy.h
│ ├── zstd_ldm.c
│ ├── zstd_ldm.h
│ ├── zstd_ldm_geartab.h
│ ├── zstd_opt.c
│ ├── zstd_opt.h
│ ├── zstdmt_compress.c
│ └── zstdmt_compress.h
│ ├── decompress
│ ├── huf_decompress.c
│ ├── zstd_ddict.c
│ ├── zstd_ddict.h
│ ├── zstd_decompress.c
│ ├── zstd_decompress_block.c
│ ├── zstd_decompress_block.h
│ └── zstd_decompress_internal.h
│ ├── dictBuilder
│ ├── cover.c
│ ├── cover.h
│ ├── divsufsort.c
│ ├── divsufsort.h
│ ├── fastcover.c
│ └── zdict.c
│ ├── zdict.h
│ ├── zstd.h
│ └── zstd_errors.h
├── LICENSE
├── PKWARE_ZIPSPEC_APPNOTE.txt
├── README.md
├── Support
└── module.modulemap
├── ZipUtilities.podspec
├── ZipUtilities.xcodeproj
├── project.pbxproj
├── project.xcworkspace
│ ├── contents.xcworkspacedata
│ └── xcshareddata
│ │ └── IDEWorkspaceChecks.plist
└── xcshareddata
│ └── xcschemes
│ ├── ZipUtilities Framework.xcscheme
│ ├── ZipUtilities OSX Framework.xcscheme
│ ├── ZipUtilities.xcscheme
│ ├── ZipUtilitiesApp.xcscheme
│ ├── libZipUtilities-mac.xcscheme
│ ├── libbrotli-mac.xcscheme
│ ├── libbrotli.xcscheme
│ ├── libzstd-mac.xcscheme
│ ├── libzstd.xcscheme
│ ├── noz -Release.xcscheme
│ └── noz.xcscheme
├── ZipUtilities
├── Info.plist
├── NOZCompress.h
├── NOZCompress.m
├── NOZCompression.h
├── NOZCompressionLibrary.h
├── NOZCompressionLibrary.m
├── NOZDecoder.h
├── NOZDecompress.h
├── NOZDecompress.m
├── NOZDeflateCoders.m
├── NOZEncoder.h
├── NOZError.h
├── NOZError.m
├── NOZRawCoders.m
├── NOZSyncStepOperation.h
├── NOZSyncStepOperation.m
├── NOZUnzipper.h
├── NOZUnzipper.m
├── NOZUtils.h
├── NOZUtils.m
├── NOZUtils_Project.h
├── NOZZipEntry.h
├── NOZZipEntry.m
├── NOZZipper.h
├── NOZZipper.m
├── NOZ_Project.h
├── NOZ_Project.m
├── NSData+NOZAdditions.h
├── NSData+NOZAdditions.m
├── NSStream+NOZAdditions.h
├── NSStream+NOZAdditions.m
├── OSX-Info.plist
└── ZipUtilities.h
├── ZipUtilitiesApp
├── AppDelegate.h
├── AppDelegate.m
├── Assets.xcassets
│ └── AppIcon.appiconset
│ │ └── Contents.json
├── Base.lproj
│ └── LaunchScreen.storyboard
├── Info.plist
├── ViewController.h
├── ViewController.m
└── main.m
├── ZipUtilitiesTests
├── Aesop.txt
├── Aesop_cp437.zip
├── Bad_File.zip
├── Data.zip
├── Directory.zip
├── File.zip
├── File2.zip
├── FrameworkTests-Bridging-Header.h
├── Info.plist
├── Mixed.zip
├── NOZCoderTests.m
├── NOZCompressTests.m
├── NOZDecompressTests.m
├── NOZSwiftTests.swift
├── Star.Wars.7.Trailer.mp4
├── Star.Wars.7.Trailer.mp4.zip
├── book.zstd_dict
├── htl.1024.zstd_dict
├── htl.128.zstd_dict
├── htl.256.zstd_dict
├── htl.512.zstd_dict
├── maniac-mansion
│ ├── Game
│ │ ├── 00.LFL
│ │ ├── 01.LFL
│ │ ├── 02.LFL
│ │ ├── 03.LFL
│ │ ├── 04.LFL
│ │ ├── 05.LFL
│ │ ├── 06.LFL
│ │ ├── 07.LFL
│ │ ├── 08.LFL
│ │ ├── 09.LFL
│ │ ├── 10.LFL
│ │ ├── 11.LFL
│ │ ├── 12.LFL
│ │ ├── 13.LFL
│ │ ├── 14.LFL
│ │ ├── 15.LFL
│ │ ├── 16.LFL
│ │ ├── 17.LFL
│ │ ├── 18.LFL
│ │ ├── 19.LFL
│ │ ├── 20.LFL
│ │ ├── 21.LFL
│ │ ├── 22.LFL
│ │ ├── 23.LFL
│ │ ├── 24.LFL
│ │ ├── 25.LFL
│ │ ├── 26.LFL
│ │ ├── 27.LFL
│ │ ├── 28.LFL
│ │ ├── 29.LFL
│ │ ├── 30.LFL
│ │ ├── 31.LFL
│ │ ├── 32.LFL
│ │ ├── 33.LFL
│ │ ├── 34.LFL
│ │ ├── 35.LFL
│ │ ├── 36.LFL
│ │ ├── 37.LFL
│ │ ├── 38.LFL
│ │ ├── 39.LFL
│ │ ├── 40.LFL
│ │ ├── 41.LFL
│ │ ├── 42.LFL
│ │ ├── 43.LFL
│ │ ├── 44.LFL
│ │ ├── 45.LFL
│ │ ├── 46.LFL
│ │ ├── 47.LFL
│ │ ├── 48.LFL
│ │ ├── 49.LFL
│ │ ├── 50.LFL
│ │ ├── 51.LFL
│ │ ├── 52.LFL
│ │ └── MANIAC.EXE
│ ├── Walkthrough
│ │ └── walkthrough.txt
│ └── ca1.jpeg
└── timeline.json
└── noz
├── NOZCLI.h
├── NOZCLI.m
├── NOZCLICompressMode.h
├── NOZCLICompressMode.m
├── NOZCLIDecompressMode.h
├── NOZCLIDecompressMode.m
├── NOZCLIDumpMode.h
├── NOZCLIDumpMode.m
├── NOZCLIMethodMode.h
├── NOZCLIMethodMode.m
├── NOZCLIModeProtocol.h
├── NOZCLIUnzipMode.h
├── NOZCLIUnzipMode.m
├── NOZCLIZipMode.h
├── NOZCLIZipMode.m
└── main.m
/.gitignore:
--------------------------------------------------------------------------------
1 | ZipUtilities/ZipUtilities.xcodeproj/project.xcworkspace/xcuserdata
2 | ZipUtilities/ZipUtilities.xcodeproj/xcuserdata
3 | docset-installed.txt
4 | ZipUtilities.xcodeproj/project.xcworkspace/xcshareddata/ZipUtilities.xccheckout
5 | ZipUtilities.xcodeproj/xcuserdata
6 | ZipUtilities.xcodeproj/project.xcworkspace/xcuserdata
7 | build
8 |
--------------------------------------------------------------------------------
/.swift-version:
--------------------------------------------------------------------------------
1 | 4.2
2 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | osx_image: xcode11.0
2 | language: objective-c
3 | script:
4 | # iOS Static Lib
5 | - xcodebuild -destination "platform=iOS Simulator,name=iPhone 8" -project ZipUtilities.xcodeproj -scheme ZipUtilities -sdk iphonesimulator clean test
6 | # iOS Framework (disabled since it requires code signing with latest Xcode and we don't provide a code signer with the open source project)
7 | #- xcodebuild -destination "platform=iOS Simulator,name=iPhone 7" -project ZipUtilities.xcodeproj -scheme "ZipUtilities Framework" -sdk iphonesimulator clean test
8 | # Mac OS X (macOS) Framework
9 | - xcodebuild -project ZipUtilities.xcodeproj -scheme "ZipUtilities OSX Framework" clean test
10 |
--------------------------------------------------------------------------------
/AppledocSettings.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | --project-name
6 | ZipUtilities
7 | --project-company
8 | Nolan O'Brien
9 | --input
10 |
11 | ZipUtilities
12 |
13 | --ignore
14 |
15 | *_Project.h
16 | *.m
17 | ZipUtilities/crypt/*
18 |
19 | --keep-undocumented-objects
20 |
21 | --keep-undocumented-members
22 |
23 | --merge-categories
24 |
25 | --merge-category-comment
26 |
27 | --use-code-order
28 |
29 | --repeat-first-par
30 |
31 | --keep-intermediate-files
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/Extra/NOZXAppleCompressionCoder.h:
--------------------------------------------------------------------------------
1 | //
2 | // NOZXAppleCompressionCoder.h
3 | // ZipUtilities
4 | //
5 | // Created by Nolan O'Brien on 9/12/15.
6 | // Copyright © 2015 NSProgrammer. All rights reserved.
7 | //
8 |
9 | #import
10 | #import
11 |
12 | @protocol NOZEncoder;
13 | @protocol NOZDecoder;
14 |
15 | @interface NOZXAppleCompressionCoder : NSObject
16 |
17 | + (BOOL)isSupported;
18 |
19 | + (nullable id)encoderWithAlgorithm:(compression_algorithm)algorithm;
20 | + (nullable id)decoderWithAlgorithm:(compression_algorithm)algorithm;
21 |
22 | - (nonnull instancetype)init NS_UNAVAILABLE;
23 | + (nonnull instancetype)new NS_UNAVAILABLE;
24 |
25 | @end
26 |
--------------------------------------------------------------------------------
/Extra/NOZXBrotliCompressionCoder.h:
--------------------------------------------------------------------------------
1 | //
2 | // NOZXBrotliCompressionCoder.h
3 | // ZipUtilities
4 | //
5 | // Created by Nolan O'Brien on 11/21/16.
6 | // Copyright © 2016 NSProgrammer. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @protocol NOZEncoder;
12 | @protocol NOZDecoder;
13 |
14 | @interface NOZXBrotliCompressionCoder : NSObject
15 |
16 | + (nullable id)encoder;
17 | + (nullable id)decoder;
18 |
19 | - (nonnull instancetype)init NS_UNAVAILABLE;
20 | + (nonnull instancetype)new NS_UNAVAILABLE;
21 |
22 | @end
23 |
--------------------------------------------------------------------------------
/Extra/NOZXZStandardCompressionCoder.h:
--------------------------------------------------------------------------------
1 | //
2 | // NOZXZStandardCompressionCoder.h
3 | // ZipUtilities
4 | //
5 | // Created by Nolan O'Brien on 11/15/16.
6 | // Copyright © 2016 NSProgrammer. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @protocol NOZEncoder;
12 | @protocol NOZDecoder;
13 |
14 | @interface NOZXZStandardCompressionCoder : NSObject
15 |
16 | + (nullable id)encoder;
17 | + (nullable id)encoderWithDictionaryData:(nullable NSData *)dict;
18 | + (nullable id)decoder;
19 | + (nullable id)decoderWithDictionaryData:(nullable NSData *)dict;
20 |
21 | - (nonnull instancetype)init NS_UNAVAILABLE;
22 | + (nonnull instancetype)new NS_UNAVAILABLE;
23 |
24 | @end
25 |
--------------------------------------------------------------------------------
/Extra/brotli/common/constants.c:
--------------------------------------------------------------------------------
1 | /* Copyright 2013 Google Inc. All Rights Reserved.
2 |
3 | Distributed under MIT license.
4 | See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
5 | */
6 |
7 | #include "./constants.h"
8 |
9 | const BrotliPrefixCodeRange
10 | _kBrotliPrefixCodeRanges[BROTLI_NUM_BLOCK_LEN_SYMBOLS] = {
11 | {1, 2}, {5, 2}, {9, 2}, {13, 2}, {17, 3}, {25, 3},
12 | {33, 3}, {41, 3}, {49, 4}, {65, 4}, {81, 4}, {97, 4},
13 | {113, 5}, {145, 5}, {177, 5}, {209, 5}, {241, 6}, {305, 6},
14 | {369, 7}, {497, 8}, {753, 9}, {1265, 10}, {2289, 11}, {4337, 12},
15 | {8433, 13}, {16625, 24}};
16 |
--------------------------------------------------------------------------------
/Extra/brotli/common/dictionary.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NSProgrammer/ZipUtilities/7152d58805eaf332ca24b8f460e4074b7ce32216/Extra/brotli/common/dictionary.bin
--------------------------------------------------------------------------------
/Extra/brotli/common/dictionary.bin.br:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NSProgrammer/ZipUtilities/7152d58805eaf332ca24b8f460e4074b7ce32216/Extra/brotli/common/dictionary.bin.br
--------------------------------------------------------------------------------
/Extra/brotli/common/dictionary.h:
--------------------------------------------------------------------------------
1 | /* Copyright 2013 Google Inc. All Rights Reserved.
2 |
3 | Distributed under MIT license.
4 | See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
5 | */
6 |
7 | /* Collection of static dictionary words. */
8 |
9 | #ifndef BROTLI_COMMON_DICTIONARY_H_
10 | #define BROTLI_COMMON_DICTIONARY_H_
11 |
12 | #include
13 | #include
14 |
15 | #if defined(__cplusplus) || defined(c_plusplus)
16 | extern "C" {
17 | #endif
18 |
19 | typedef struct BrotliDictionary {
20 | /**
21 | * Number of bits to encode index of dictionary word in a bucket.
22 | *
23 | * Specification: Appendix A. Static Dictionary Data
24 | *
25 | * Words in a dictionary are bucketed by length.
26 | * @c 0 means that there are no words of a given length.
27 | * Dictionary consists of words with length of [4..24] bytes.
28 | * Values at [0..3] and [25..31] indices should not be addressed.
29 | */
30 | uint8_t size_bits_by_length[32];
31 |
32 | /* assert(offset[i + 1] == offset[i] + (bits[i] ? (i << bits[i]) : 0)) */
33 | uint32_t offsets_by_length[32];
34 |
35 | /* assert(data_size == offsets_by_length[31]) */
36 | size_t data_size;
37 |
38 | /* Data array is not bound, and should obey to size_bits_by_length values.
39 | Specified size matches default (RFC 7932) dictionary. Its size is
40 | defined by data_size */
41 | const uint8_t* data;
42 | } BrotliDictionary;
43 |
44 | BROTLI_COMMON_API const BrotliDictionary* BrotliGetDictionary(void);
45 |
46 | /**
47 | * Sets dictionary data.
48 | *
49 | * When dictionary data is already set / present, this method is no-op.
50 | *
51 | * Dictionary data MUST be provided before BrotliGetDictionary is invoked.
52 | * This method is used ONLY in multi-client environment (e.g. C + Java),
53 | * to reduce storage by sharing single dictionary between implementations.
54 | */
55 | BROTLI_COMMON_API void BrotliSetDictionaryData(const uint8_t* data);
56 |
57 | #define BROTLI_MIN_DICTIONARY_WORD_LENGTH 4
58 | #define BROTLI_MAX_DICTIONARY_WORD_LENGTH 24
59 |
60 | #if defined(__cplusplus) || defined(c_plusplus)
61 | } /* extern "C" */
62 | #endif
63 |
64 | #endif /* BROTLI_COMMON_DICTIONARY_H_ */
65 |
--------------------------------------------------------------------------------
/Extra/brotli/common/platform.c:
--------------------------------------------------------------------------------
1 | /* Copyright 2016 Google Inc. All Rights Reserved.
2 |
3 | Distributed under MIT license.
4 | See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
5 | */
6 |
7 | #include
8 |
9 | #include "./platform.h"
10 | #include
11 |
12 | /* Default brotli_alloc_func */
13 | void* BrotliDefaultAllocFunc(void* opaque, size_t size) {
14 | BROTLI_UNUSED(opaque);
15 | return malloc(size);
16 | }
17 |
18 | /* Default brotli_free_func */
19 | void BrotliDefaultFreeFunc(void* opaque, void* address) {
20 | BROTLI_UNUSED(opaque);
21 | free(address);
22 | }
23 |
--------------------------------------------------------------------------------
/Extra/brotli/common/transform.h:
--------------------------------------------------------------------------------
1 | /* transforms is a part of ABI, but not API.
2 |
3 | It means that there are some functions that are supposed to be in "common"
4 | library, but header itself is not placed into include/brotli. This way,
5 | aforementioned functions will be available only to brotli internals.
6 | */
7 |
8 | #ifndef BROTLI_COMMON_TRANSFORM_H_
9 | #define BROTLI_COMMON_TRANSFORM_H_
10 |
11 | #include
12 | #include
13 |
14 | #if defined(__cplusplus) || defined(c_plusplus)
15 | extern "C" {
16 | #endif
17 |
18 | enum BrotliWordTransformType {
19 | BROTLI_TRANSFORM_IDENTITY = 0,
20 | BROTLI_TRANSFORM_OMIT_LAST_1 = 1,
21 | BROTLI_TRANSFORM_OMIT_LAST_2 = 2,
22 | BROTLI_TRANSFORM_OMIT_LAST_3 = 3,
23 | BROTLI_TRANSFORM_OMIT_LAST_4 = 4,
24 | BROTLI_TRANSFORM_OMIT_LAST_5 = 5,
25 | BROTLI_TRANSFORM_OMIT_LAST_6 = 6,
26 | BROTLI_TRANSFORM_OMIT_LAST_7 = 7,
27 | BROTLI_TRANSFORM_OMIT_LAST_8 = 8,
28 | BROTLI_TRANSFORM_OMIT_LAST_9 = 9,
29 | BROTLI_TRANSFORM_UPPERCASE_FIRST = 10,
30 | BROTLI_TRANSFORM_UPPERCASE_ALL = 11,
31 | BROTLI_TRANSFORM_OMIT_FIRST_1 = 12,
32 | BROTLI_TRANSFORM_OMIT_FIRST_2 = 13,
33 | BROTLI_TRANSFORM_OMIT_FIRST_3 = 14,
34 | BROTLI_TRANSFORM_OMIT_FIRST_4 = 15,
35 | BROTLI_TRANSFORM_OMIT_FIRST_5 = 16,
36 | BROTLI_TRANSFORM_OMIT_FIRST_6 = 17,
37 | BROTLI_TRANSFORM_OMIT_FIRST_7 = 18,
38 | BROTLI_TRANSFORM_OMIT_FIRST_8 = 19,
39 | BROTLI_TRANSFORM_OMIT_FIRST_9 = 20,
40 | BROTLI_TRANSFORM_SHIFT_FIRST = 21,
41 | BROTLI_TRANSFORM_SHIFT_ALL = 22,
42 | BROTLI_NUM_TRANSFORM_TYPES /* Counts transforms, not a transform itself. */
43 | };
44 |
45 | #define BROTLI_TRANSFORMS_MAX_CUT_OFF BROTLI_TRANSFORM_OMIT_LAST_9
46 |
47 | typedef struct BrotliTransforms {
48 | uint16_t prefix_suffix_size;
49 | /* Last character must be null, so prefix_suffix_size must be at least 1. */
50 | const uint8_t* prefix_suffix;
51 | const uint16_t* prefix_suffix_map;
52 | uint32_t num_transforms;
53 | /* Each entry is a [prefix_id, transform, suffix_id] triplet. */
54 | const uint8_t* transforms;
55 | /* Shift for BROTLI_TRANSFORM_SHIFT_FIRST and BROTLI_TRANSFORM_SHIFT_ALL,
56 | must be NULL if and only if no such transforms are present. */
57 | const uint8_t* params;
58 | /* Indices of transforms like ["", BROTLI_TRANSFORM_OMIT_LAST_#, ""].
59 | 0-th element corresponds to ["", BROTLI_TRANSFORM_IDENTITY, ""].
60 | -1, if cut-off transform does not exist. */
61 | int16_t cutOffTransforms[BROTLI_TRANSFORMS_MAX_CUT_OFF + 1];
62 | } BrotliTransforms;
63 |
64 | /* T is BrotliTransforms*; result is uint8_t. */
65 | #define BROTLI_TRANSFORM_PREFIX_ID(T, I) ((T)->transforms[((I) * 3) + 0])
66 | #define BROTLI_TRANSFORM_TYPE(T, I) ((T)->transforms[((I) * 3) + 1])
67 | #define BROTLI_TRANSFORM_SUFFIX_ID(T, I) ((T)->transforms[((I) * 3) + 2])
68 |
69 | /* T is BrotliTransforms*; result is const uint8_t*. */
70 | #define BROTLI_TRANSFORM_PREFIX(T, I) (&(T)->prefix_suffix[ \
71 | (T)->prefix_suffix_map[BROTLI_TRANSFORM_PREFIX_ID(T, I)]])
72 | #define BROTLI_TRANSFORM_SUFFIX(T, I) (&(T)->prefix_suffix[ \
73 | (T)->prefix_suffix_map[BROTLI_TRANSFORM_SUFFIX_ID(T, I)]])
74 |
75 | BROTLI_COMMON_API const BrotliTransforms* BrotliGetTransforms(void);
76 |
77 | BROTLI_COMMON_API int BrotliTransformDictionaryWord(
78 | uint8_t* dst, const uint8_t* word, int len,
79 | const BrotliTransforms* transforms, int transform_idx);
80 |
81 | #if defined(__cplusplus) || defined(c_plusplus)
82 | } /* extern "C" */
83 | #endif
84 |
85 | #endif /* BROTLI_COMMON_TRANSFORM_H_ */
86 |
--------------------------------------------------------------------------------
/Extra/brotli/common/version.h:
--------------------------------------------------------------------------------
1 | /* Copyright 2016 Google Inc. All Rights Reserved.
2 |
3 | Distributed under MIT license.
4 | See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
5 | */
6 |
7 | /* Version definition. */
8 |
9 | #ifndef BROTLI_COMMON_VERSION_H_
10 | #define BROTLI_COMMON_VERSION_H_
11 |
12 | /* This macro should only be used when library is compiled together with client.
13 | If library is dynamically linked, use BrotliDecoderVersion and
14 | BrotliEncoderVersion methods. */
15 |
16 | /* Semantic version, calculated as (MAJOR << 24) | (MINOR << 12) | PATCH */
17 | #define BROTLI_VERSION 0x1000009
18 |
19 | /* This macro is used by build system to produce Libtool-friendly soname. See
20 | https://www.gnu.org/software/libtool/manual/html_node/Libtool-versioning.html
21 | */
22 |
23 | /* ABI version, calculated as (CURRENT << 24) | (REVISION << 12) | AGE */
24 | #define BROTLI_ABI_VERSION 0x1009000
25 |
26 | #endif /* BROTLI_COMMON_VERSION_H_ */
27 |
--------------------------------------------------------------------------------
/Extra/brotli/dec/bit_reader.c:
--------------------------------------------------------------------------------
1 | /* Copyright 2013 Google Inc. All Rights Reserved.
2 |
3 | Distributed under MIT license.
4 | See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
5 | */
6 |
7 | /* Bit reading helpers */
8 |
9 | #include "./bit_reader.h"
10 |
11 | #include "../common/platform.h"
12 | #include
13 |
14 | #if defined(__cplusplus) || defined(c_plusplus)
15 | extern "C" {
16 | #endif
17 |
18 | const uint32_t kBrotliBitMask[33] = { 0x00000000,
19 | 0x00000001, 0x00000003, 0x00000007, 0x0000000F,
20 | 0x0000001F, 0x0000003F, 0x0000007F, 0x000000FF,
21 | 0x000001FF, 0x000003FF, 0x000007FF, 0x00000FFF,
22 | 0x00001FFF, 0x00003FFF, 0x00007FFF, 0x0000FFFF,
23 | 0x0001FFFF, 0x0003FFFF, 0x0007FFFF, 0x000FFFFF,
24 | 0x001FFFFF, 0x003FFFFF, 0x007FFFFF, 0x00FFFFFF,
25 | 0x01FFFFFF, 0x03FFFFFF, 0x07FFFFFF, 0x0FFFFFFF,
26 | 0x1FFFFFFF, 0x3FFFFFFF, 0x7FFFFFFF, 0xFFFFFFFF
27 | };
28 |
29 | void BrotliInitBitReader(BrotliBitReader* const br) {
30 | br->val_ = 0;
31 | br->bit_pos_ = sizeof(br->val_) << 3;
32 | }
33 |
34 | BROTLI_BOOL BrotliWarmupBitReader(BrotliBitReader* const br) {
35 | size_t aligned_read_mask = (sizeof(br->val_) >> 1) - 1;
36 | /* Fixing alignment after unaligned BrotliFillWindow would result accumulator
37 | overflow. If unalignment is caused by BrotliSafeReadBits, then there is
38 | enough space in accumulator to fix alignment. */
39 | if (!BROTLI_ALIGNED_READ) {
40 | aligned_read_mask = 0;
41 | }
42 | if (BrotliGetAvailableBits(br) == 0) {
43 | if (!BrotliPullByte(br)) {
44 | return BROTLI_FALSE;
45 | }
46 | }
47 |
48 | while ((((size_t)br->next_in) & aligned_read_mask) != 0) {
49 | if (!BrotliPullByte(br)) {
50 | /* If we consumed all the input, we don't care about the alignment. */
51 | return BROTLI_TRUE;
52 | }
53 | }
54 | return BROTLI_TRUE;
55 | }
56 |
57 | BROTLI_BOOL BrotliSafeReadBits32Slow(BrotliBitReader* const br,
58 | uint32_t n_bits, uint32_t* val) {
59 | uint32_t low_val;
60 | uint32_t high_val;
61 | BrotliBitReaderState memento;
62 | BROTLI_DCHECK(n_bits <= 32);
63 | BROTLI_DCHECK(n_bits > 24);
64 | BrotliBitReaderSaveState(br, &memento);
65 | if (!BrotliSafeReadBits(br, 16, &low_val) ||
66 | !BrotliSafeReadBits(br, n_bits - 16, &high_val)) {
67 | BrotliBitReaderRestoreState(br, &memento);
68 | return BROTLI_FALSE;
69 | }
70 | *val = low_val | (high_val << 16);
71 | return BROTLI_TRUE;
72 | }
73 |
74 | #if defined(__cplusplus) || defined(c_plusplus)
75 | } /* extern "C" */
76 | #endif
77 |
--------------------------------------------------------------------------------
/Extra/brotli/enc/backward_references.h:
--------------------------------------------------------------------------------
1 | /* Copyright 2013 Google Inc. All Rights Reserved.
2 |
3 | Distributed under MIT license.
4 | See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
5 | */
6 |
7 | /* Function to find backward reference copies. */
8 |
9 | #ifndef BROTLI_ENC_BACKWARD_REFERENCES_H_
10 | #define BROTLI_ENC_BACKWARD_REFERENCES_H_
11 |
12 | #include "../common/constants.h"
13 | #include "../common/context.h"
14 | #include "../common/dictionary.h"
15 | #include "../common/platform.h"
16 | #include
17 | #include "./command.h"
18 | #include "./hash.h"
19 | #include "./quality.h"
20 |
21 | #if defined(__cplusplus) || defined(c_plusplus)
22 | extern "C" {
23 | #endif
24 |
25 | /* "commands" points to the next output command to write to, "*num_commands" is
26 | initially the total amount of commands output by previous
27 | CreateBackwardReferences calls, and must be incremented by the amount written
28 | by this call. */
29 | BROTLI_INTERNAL void BrotliCreateBackwardReferences(size_t num_bytes,
30 | size_t position, const uint8_t* ringbuffer, size_t ringbuffer_mask,
31 | ContextLut literal_context_lut, const BrotliEncoderParams* params,
32 | Hasher* hasher, int* dist_cache, size_t* last_insert_len,
33 | Command* commands, size_t* num_commands, size_t* num_literals);
34 |
35 | #if defined(__cplusplus) || defined(c_plusplus)
36 | } /* extern "C" */
37 | #endif
38 |
39 | #endif /* BROTLI_ENC_BACKWARD_REFERENCES_H_ */
40 |
--------------------------------------------------------------------------------
/Extra/brotli/enc/backward_references_hq.h:
--------------------------------------------------------------------------------
1 | /* Copyright 2013 Google Inc. All Rights Reserved.
2 |
3 | Distributed under MIT license.
4 | See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
5 | */
6 |
7 | /* Function to find backward reference copies. */
8 |
9 | #ifndef BROTLI_ENC_BACKWARD_REFERENCES_HQ_H_
10 | #define BROTLI_ENC_BACKWARD_REFERENCES_HQ_H_
11 |
12 | #include "../common/constants.h"
13 | #include "../common/context.h"
14 | #include "../common/dictionary.h"
15 | #include "../common/platform.h"
16 | #include
17 | #include "./command.h"
18 | #include "./hash.h"
19 | #include "./memory.h"
20 | #include "./quality.h"
21 |
22 | #if defined(__cplusplus) || defined(c_plusplus)
23 | extern "C" {
24 | #endif
25 |
26 | BROTLI_INTERNAL void BrotliCreateZopfliBackwardReferences(MemoryManager* m,
27 | size_t num_bytes,
28 | size_t position, const uint8_t* ringbuffer, size_t ringbuffer_mask,
29 | ContextLut literal_context_lut, const BrotliEncoderParams* params,
30 | Hasher* hasher, int* dist_cache, size_t* last_insert_len,
31 | Command* commands, size_t* num_commands, size_t* num_literals);
32 |
33 | BROTLI_INTERNAL void BrotliCreateHqZopfliBackwardReferences(MemoryManager* m,
34 | size_t num_bytes,
35 | size_t position, const uint8_t* ringbuffer, size_t ringbuffer_mask,
36 | ContextLut literal_context_lut, const BrotliEncoderParams* params,
37 | Hasher* hasher, int* dist_cache, size_t* last_insert_len,
38 | Command* commands, size_t* num_commands, size_t* num_literals);
39 |
40 | typedef struct ZopfliNode {
41 | /* Best length to get up to this byte (not including this byte itself)
42 | highest 7 bit is used to reconstruct the length code. */
43 | uint32_t length;
44 | /* Distance associated with the length. */
45 | uint32_t distance;
46 | /* Number of literal inserts before this copy; highest 5 bits contain
47 | distance short code + 1 (or zero if no short code). */
48 | uint32_t dcode_insert_length;
49 |
50 | /* This union holds information used by dynamic-programming. During forward
51 | pass |cost| it used to store the goal function. When node is processed its
52 | |cost| is invalidated in favor of |shortcut|. On path back-tracing pass
53 | |next| is assigned the offset to next node on the path. */
54 | union {
55 | /* Smallest cost to get to this byte from the beginning, as found so far. */
56 | float cost;
57 | /* Offset to the next node on the path. Equals to command_length() of the
58 | next node on the path. For last node equals to BROTLI_UINT32_MAX */
59 | uint32_t next;
60 | /* Node position that provides next distance for distance cache. */
61 | uint32_t shortcut;
62 | } u;
63 | } ZopfliNode;
64 |
65 | BROTLI_INTERNAL void BrotliInitZopfliNodes(ZopfliNode* array, size_t length);
66 |
67 | /* Computes the shortest path of commands from position to at most
68 | position + num_bytes.
69 |
70 | On return, path->size() is the number of commands found and path[i] is the
71 | length of the i-th command (copy length plus insert length).
72 | Note that the sum of the lengths of all commands can be less than num_bytes.
73 |
74 | On return, the nodes[0..num_bytes] array will have the following
75 | "ZopfliNode array invariant":
76 | For each i in [1..num_bytes], if nodes[i].cost < kInfinity, then
77 | (1) nodes[i].copy_length() >= 2
78 | (2) nodes[i].command_length() <= i and
79 | (3) nodes[i - nodes[i].command_length()].cost < kInfinity */
80 | BROTLI_INTERNAL size_t BrotliZopfliComputeShortestPath(
81 | MemoryManager* m, size_t num_bytes,
82 | size_t position, const uint8_t* ringbuffer, size_t ringbuffer_mask,
83 | ContextLut literal_context_lut, const BrotliEncoderParams* params,
84 | const int* dist_cache, Hasher* hasher, ZopfliNode* nodes);
85 |
86 | BROTLI_INTERNAL void BrotliZopfliCreateCommands(
87 | const size_t num_bytes, const size_t block_start, const ZopfliNode* nodes,
88 | int* dist_cache, size_t* last_insert_len, const BrotliEncoderParams* params,
89 | Command* commands, size_t* num_literals);
90 |
91 | #if defined(__cplusplus) || defined(c_plusplus)
92 | } /* extern "C" */
93 | #endif
94 |
95 | #endif /* BROTLI_ENC_BACKWARD_REFERENCES_HQ_H_ */
96 |
--------------------------------------------------------------------------------
/Extra/brotli/enc/bit_cost.c:
--------------------------------------------------------------------------------
1 | /* Copyright 2013 Google Inc. All Rights Reserved.
2 |
3 | Distributed under MIT license.
4 | See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
5 | */
6 |
7 | /* Functions to estimate the bit cost of Huffman trees. */
8 |
9 | #include "./bit_cost.h"
10 |
11 | #include "../common/constants.h"
12 | #include "../common/platform.h"
13 | #include
14 | #include "./fast_log.h"
15 | #include "./histogram.h"
16 |
17 | #if defined(__cplusplus) || defined(c_plusplus)
18 | extern "C" {
19 | #endif
20 |
21 | #define FN(X) X ## Literal
22 | #include "./bit_cost_inc.h" /* NOLINT(build/include) */
23 | #undef FN
24 |
25 | #define FN(X) X ## Command
26 | #include "./bit_cost_inc.h" /* NOLINT(build/include) */
27 | #undef FN
28 |
29 | #define FN(X) X ## Distance
30 | #include "./bit_cost_inc.h" /* NOLINT(build/include) */
31 | #undef FN
32 |
33 | #if defined(__cplusplus) || defined(c_plusplus)
34 | } /* extern "C" */
35 | #endif
36 |
--------------------------------------------------------------------------------
/Extra/brotli/enc/bit_cost.h:
--------------------------------------------------------------------------------
1 | /* Copyright 2013 Google Inc. All Rights Reserved.
2 |
3 | Distributed under MIT license.
4 | See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
5 | */
6 |
7 | /* Functions to estimate the bit cost of Huffman trees. */
8 |
9 | #ifndef BROTLI_ENC_BIT_COST_H_
10 | #define BROTLI_ENC_BIT_COST_H_
11 |
12 | #include "../common/platform.h"
13 | #include
14 | #include "./fast_log.h"
15 | #include "./histogram.h"
16 |
17 | #if defined(__cplusplus) || defined(c_plusplus)
18 | extern "C" {
19 | #endif
20 |
21 | static BROTLI_INLINE double ShannonEntropy(
22 | const uint32_t* population, size_t size, size_t* total) {
23 | size_t sum = 0;
24 | double retval = 0;
25 | const uint32_t* population_end = population + size;
26 | size_t p;
27 | if (size & 1) {
28 | goto odd_number_of_elements_left;
29 | }
30 | while (population < population_end) {
31 | p = *population++;
32 | sum += p;
33 | retval -= (double)p * FastLog2(p);
34 | odd_number_of_elements_left:
35 | p = *population++;
36 | sum += p;
37 | retval -= (double)p * FastLog2(p);
38 | }
39 | if (sum) retval += (double)sum * FastLog2(sum);
40 | *total = sum;
41 | return retval;
42 | }
43 |
44 | static BROTLI_INLINE double BitsEntropy(
45 | const uint32_t* population, size_t size) {
46 | size_t sum;
47 | double retval = ShannonEntropy(population, size, &sum);
48 | if (retval < sum) {
49 | /* At least one bit per literal is needed. */
50 | retval = (double)sum;
51 | }
52 | return retval;
53 | }
54 |
55 | BROTLI_INTERNAL double BrotliPopulationCostLiteral(const HistogramLiteral*);
56 | BROTLI_INTERNAL double BrotliPopulationCostCommand(const HistogramCommand*);
57 | BROTLI_INTERNAL double BrotliPopulationCostDistance(const HistogramDistance*);
58 |
59 | #if defined(__cplusplus) || defined(c_plusplus)
60 | } /* extern "C" */
61 | #endif
62 |
63 | #endif /* BROTLI_ENC_BIT_COST_H_ */
64 |
--------------------------------------------------------------------------------
/Extra/brotli/enc/block_encoder_inc.h:
--------------------------------------------------------------------------------
1 | /* NOLINT(build/header_guard) */
2 | /* Copyright 2014 Google Inc. All Rights Reserved.
3 |
4 | Distributed under MIT license.
5 | See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
6 | */
7 |
8 | /* template parameters: FN */
9 |
10 | #define HistogramType FN(Histogram)
11 |
12 | /* Creates entropy codes for all block types and stores them to the bit
13 | stream. */
14 | static void FN(BuildAndStoreEntropyCodes)(MemoryManager* m, BlockEncoder* self,
15 | const HistogramType* histograms, const size_t histograms_size,
16 | const size_t alphabet_size, HuffmanTree* tree,
17 | size_t* storage_ix, uint8_t* storage) {
18 | const size_t table_size = histograms_size * self->histogram_length_;
19 | self->depths_ = BROTLI_ALLOC(m, uint8_t, table_size);
20 | self->bits_ = BROTLI_ALLOC(m, uint16_t, table_size);
21 | if (BROTLI_IS_OOM(m)) return;
22 |
23 | {
24 | size_t i;
25 | for (i = 0; i < histograms_size; ++i) {
26 | size_t ix = i * self->histogram_length_;
27 | BuildAndStoreHuffmanTree(&histograms[i].data_[0], self->histogram_length_,
28 | alphabet_size, tree, &self->depths_[ix], &self->bits_[ix],
29 | storage_ix, storage);
30 | }
31 | }
32 | }
33 |
34 | #undef HistogramType
35 |
--------------------------------------------------------------------------------
/Extra/brotli/enc/block_splitter.h:
--------------------------------------------------------------------------------
1 | /* Copyright 2013 Google Inc. All Rights Reserved.
2 |
3 | Distributed under MIT license.
4 | See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
5 | */
6 |
7 | /* Block split point selection utilities. */
8 |
9 | #ifndef BROTLI_ENC_BLOCK_SPLITTER_H_
10 | #define BROTLI_ENC_BLOCK_SPLITTER_H_
11 |
12 | #include "../common/platform.h"
13 | #include
14 | #include "./command.h"
15 | #include "./memory.h"
16 | #include "./quality.h"
17 |
18 | #if defined(__cplusplus) || defined(c_plusplus)
19 | extern "C" {
20 | #endif
21 |
22 | typedef struct BlockSplit {
23 | size_t num_types; /* Amount of distinct types */
24 | size_t num_blocks; /* Amount of values in types and length */
25 | uint8_t* types;
26 | uint32_t* lengths;
27 |
28 | size_t types_alloc_size;
29 | size_t lengths_alloc_size;
30 | } BlockSplit;
31 |
32 | BROTLI_INTERNAL void BrotliInitBlockSplit(BlockSplit* self);
33 | BROTLI_INTERNAL void BrotliDestroyBlockSplit(MemoryManager* m,
34 | BlockSplit* self);
35 |
36 | BROTLI_INTERNAL void BrotliSplitBlock(MemoryManager* m,
37 | const Command* cmds,
38 | const size_t num_commands,
39 | const uint8_t* data,
40 | const size_t offset,
41 | const size_t mask,
42 | const BrotliEncoderParams* params,
43 | BlockSplit* literal_split,
44 | BlockSplit* insert_and_copy_split,
45 | BlockSplit* dist_split);
46 |
47 | #if defined(__cplusplus) || defined(c_plusplus)
48 | } /* extern "C" */
49 | #endif
50 |
51 | #endif /* BROTLI_ENC_BLOCK_SPLITTER_H_ */
52 |
--------------------------------------------------------------------------------
/Extra/brotli/enc/brotli_bit_stream.h:
--------------------------------------------------------------------------------
1 | /* Copyright 2014 Google Inc. All Rights Reserved.
2 |
3 | Distributed under MIT license.
4 | See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
5 | */
6 |
7 | /* Functions to convert brotli-related data structures into the
8 | brotli bit stream. The functions here operate under
9 | assumption that there is enough space in the storage, i.e., there are
10 | no out-of-range checks anywhere.
11 |
12 | These functions do bit addressing into a byte array. The byte array
13 | is called "storage" and the index to the bit is called storage_ix
14 | in function arguments. */
15 |
16 | #ifndef BROTLI_ENC_BROTLI_BIT_STREAM_H_
17 | #define BROTLI_ENC_BROTLI_BIT_STREAM_H_
18 |
19 | #include "../common/context.h"
20 | #include "../common/platform.h"
21 | #include
22 | #include "./command.h"
23 | #include "./entropy_encode.h"
24 | #include "./memory.h"
25 | #include "./metablock.h"
26 |
27 | #if defined(__cplusplus) || defined(c_plusplus)
28 | extern "C" {
29 | #endif
30 |
31 | /* All Store functions here will use a storage_ix, which is always the bit
32 | position for the current storage. */
33 |
34 | BROTLI_INTERNAL void BrotliStoreHuffmanTree(const uint8_t* depths, size_t num,
35 | HuffmanTree* tree, size_t* storage_ix, uint8_t* storage);
36 |
37 | BROTLI_INTERNAL void BrotliBuildAndStoreHuffmanTreeFast(
38 | MemoryManager* m, const uint32_t* histogram, const size_t histogram_total,
39 | const size_t max_bits, uint8_t* depth, uint16_t* bits, size_t* storage_ix,
40 | uint8_t* storage);
41 |
42 | /* REQUIRES: length > 0 */
43 | /* REQUIRES: length <= (1 << 24) */
44 | BROTLI_INTERNAL void BrotliStoreMetaBlock(MemoryManager* m,
45 | const uint8_t* input, size_t start_pos, size_t length, size_t mask,
46 | uint8_t prev_byte, uint8_t prev_byte2, BROTLI_BOOL is_last,
47 | const BrotliEncoderParams* params, ContextType literal_context_mode,
48 | const Command* commands, size_t n_commands, const MetaBlockSplit* mb,
49 | size_t* storage_ix, uint8_t* storage);
50 |
51 | /* Stores the meta-block without doing any block splitting, just collects
52 | one histogram per block category and uses that for entropy coding.
53 | REQUIRES: length > 0
54 | REQUIRES: length <= (1 << 24) */
55 | BROTLI_INTERNAL void BrotliStoreMetaBlockTrivial(MemoryManager* m,
56 | const uint8_t* input, size_t start_pos, size_t length, size_t mask,
57 | BROTLI_BOOL is_last, const BrotliEncoderParams* params,
58 | const Command* commands, size_t n_commands,
59 | size_t* storage_ix, uint8_t* storage);
60 |
61 | /* Same as above, but uses static prefix codes for histograms with a only a few
62 | symbols, and uses static code length prefix codes for all other histograms.
63 | REQUIRES: length > 0
64 | REQUIRES: length <= (1 << 24) */
65 | BROTLI_INTERNAL void BrotliStoreMetaBlockFast(MemoryManager* m,
66 | const uint8_t* input, size_t start_pos, size_t length, size_t mask,
67 | BROTLI_BOOL is_last, const BrotliEncoderParams* params,
68 | const Command* commands, size_t n_commands,
69 | size_t* storage_ix, uint8_t* storage);
70 |
71 | /* This is for storing uncompressed blocks (simple raw storage of
72 | bytes-as-bytes).
73 | REQUIRES: length > 0
74 | REQUIRES: length <= (1 << 24) */
75 | BROTLI_INTERNAL void BrotliStoreUncompressedMetaBlock(
76 | BROTLI_BOOL is_final_block, const uint8_t* BROTLI_RESTRICT input,
77 | size_t position, size_t mask, size_t len,
78 | size_t* BROTLI_RESTRICT storage_ix, uint8_t* BROTLI_RESTRICT storage);
79 |
80 | #if defined(__cplusplus) || defined(c_plusplus)
81 | } /* extern "C" */
82 | #endif
83 |
84 | #endif /* BROTLI_ENC_BROTLI_BIT_STREAM_H_ */
85 |
--------------------------------------------------------------------------------
/Extra/brotli/enc/cluster.c:
--------------------------------------------------------------------------------
1 | /* Copyright 2013 Google Inc. All Rights Reserved.
2 |
3 | Distributed under MIT license.
4 | See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
5 | */
6 |
7 | /* Functions for clustering similar histograms together. */
8 |
9 | #include "./cluster.h"
10 |
11 | #include "../common/platform.h"
12 | #include
13 | #include "./bit_cost.h" /* BrotliPopulationCost */
14 | #include "./fast_log.h"
15 | #include "./histogram.h"
16 | #include "./memory.h"
17 |
18 | #if defined(__cplusplus) || defined(c_plusplus)
19 | extern "C" {
20 | #endif
21 |
22 | static BROTLI_INLINE BROTLI_BOOL HistogramPairIsLess(
23 | const HistogramPair* p1, const HistogramPair* p2) {
24 | if (p1->cost_diff != p2->cost_diff) {
25 | return TO_BROTLI_BOOL(p1->cost_diff > p2->cost_diff);
26 | }
27 | return TO_BROTLI_BOOL((p1->idx2 - p1->idx1) > (p2->idx2 - p2->idx1));
28 | }
29 |
30 | /* Returns entropy reduction of the context map when we combine two clusters. */
31 | static BROTLI_INLINE double ClusterCostDiff(size_t size_a, size_t size_b) {
32 | size_t size_c = size_a + size_b;
33 | return (double)size_a * FastLog2(size_a) +
34 | (double)size_b * FastLog2(size_b) -
35 | (double)size_c * FastLog2(size_c);
36 | }
37 |
38 | #define CODE(X) X
39 |
40 | #define FN(X) X ## Literal
41 | #include "./cluster_inc.h" /* NOLINT(build/include) */
42 | #undef FN
43 |
44 | #define FN(X) X ## Command
45 | #include "./cluster_inc.h" /* NOLINT(build/include) */
46 | #undef FN
47 |
48 | #define FN(X) X ## Distance
49 | #include "./cluster_inc.h" /* NOLINT(build/include) */
50 | #undef FN
51 |
52 | #undef CODE
53 |
54 | #if defined(__cplusplus) || defined(c_plusplus)
55 | } /* extern "C" */
56 | #endif
57 |
--------------------------------------------------------------------------------
/Extra/brotli/enc/cluster.h:
--------------------------------------------------------------------------------
1 | /* Copyright 2013 Google Inc. All Rights Reserved.
2 |
3 | Distributed under MIT license.
4 | See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
5 | */
6 |
7 | /* Functions for clustering similar histograms together. */
8 |
9 | #ifndef BROTLI_ENC_CLUSTER_H_
10 | #define BROTLI_ENC_CLUSTER_H_
11 |
12 | #include "../common/platform.h"
13 | #include
14 | #include "./histogram.h"
15 | #include "./memory.h"
16 |
17 | #if defined(__cplusplus) || defined(c_plusplus)
18 | extern "C" {
19 | #endif
20 |
21 | typedef struct HistogramPair {
22 | uint32_t idx1;
23 | uint32_t idx2;
24 | double cost_combo;
25 | double cost_diff;
26 | } HistogramPair;
27 |
28 | #define CODE(X) /* Declaration */;
29 |
30 | #define FN(X) X ## Literal
31 | #include "./cluster_inc.h" /* NOLINT(build/include) */
32 | #undef FN
33 |
34 | #define FN(X) X ## Command
35 | #include "./cluster_inc.h" /* NOLINT(build/include) */
36 | #undef FN
37 |
38 | #define FN(X) X ## Distance
39 | #include "./cluster_inc.h" /* NOLINT(build/include) */
40 | #undef FN
41 |
42 | #undef CODE
43 |
44 | #if defined(__cplusplus) || defined(c_plusplus)
45 | } /* extern "C" */
46 | #endif
47 |
48 | #endif /* BROTLI_ENC_CLUSTER_H_ */
49 |
--------------------------------------------------------------------------------
/Extra/brotli/enc/command.c:
--------------------------------------------------------------------------------
1 | /* Copyright 2013 Google Inc. All Rights Reserved.
2 |
3 | Distributed under MIT license.
4 | See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
5 | */
6 |
7 | #include "./command.h"
8 |
9 | #include
10 |
11 | #if defined(__cplusplus) || defined(c_plusplus)
12 | extern "C" {
13 | #endif
14 |
15 | const uint32_t kBrotliInsBase[BROTLI_NUM_INS_COPY_CODES] = {
16 | 0, 1, 2, 3, 4, 5, 6, 8, 10, 14, 18, 26,
17 | 34, 50, 66, 98, 130, 194, 322, 578, 1090, 2114, 6210, 22594};
18 | const uint32_t kBrotliInsExtra[BROTLI_NUM_INS_COPY_CODES] = {
19 | 0, 0, 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 7, 8, 9, 10, 12, 14, 24};
20 | const uint32_t kBrotliCopyBase[BROTLI_NUM_INS_COPY_CODES] = {
21 | 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 18,
22 | 22, 30, 38, 54, 70, 102, 134, 198, 326, 582, 1094, 2118};
23 | const uint32_t kBrotliCopyExtra[BROTLI_NUM_INS_COPY_CODES] = {
24 | 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 7, 8, 9, 10, 24};
25 |
26 | #if defined(__cplusplus) || defined(c_plusplus)
27 | } /* extern "C" */
28 | #endif
29 |
--------------------------------------------------------------------------------
/Extra/brotli/enc/compress_fragment.h:
--------------------------------------------------------------------------------
1 | /* Copyright 2015 Google Inc. All Rights Reserved.
2 |
3 | Distributed under MIT license.
4 | See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
5 | */
6 |
7 | /* Function for fast encoding of an input fragment, independently from the input
8 | history. This function uses one-pass processing: when we find a backward
9 | match, we immediately emit the corresponding command and literal codes to
10 | the bit stream. */
11 |
12 | #ifndef BROTLI_ENC_COMPRESS_FRAGMENT_H_
13 | #define BROTLI_ENC_COMPRESS_FRAGMENT_H_
14 |
15 | #include "../common/platform.h"
16 | #include
17 | #include "./memory.h"
18 |
19 | #if defined(__cplusplus) || defined(c_plusplus)
20 | extern "C" {
21 | #endif
22 |
23 | /* Compresses "input" string to the "*storage" buffer as one or more complete
24 | meta-blocks, and updates the "*storage_ix" bit position.
25 |
26 | If "is_last" is 1, emits an additional empty last meta-block.
27 |
28 | "cmd_depth" and "cmd_bits" contain the command and distance prefix codes
29 | (see comment in encode.h) used for the encoding of this input fragment.
30 | If "is_last" is 0, they are updated to reflect the statistics
31 | of this input fragment, to be used for the encoding of the next fragment.
32 |
33 | "*cmd_code_numbits" is the number of bits of the compressed representation
34 | of the command and distance prefix codes, and "cmd_code" is an array of
35 | at least "(*cmd_code_numbits + 7) >> 3" size that contains the compressed
36 | command and distance prefix codes. If "is_last" is 0, these are also
37 | updated to represent the updated "cmd_depth" and "cmd_bits".
38 |
39 | REQUIRES: "input_size" is greater than zero, or "is_last" is 1.
40 | REQUIRES: "input_size" is less or equal to maximal metablock size (1 << 24).
41 | REQUIRES: All elements in "table[0..table_size-1]" are initialized to zero.
42 | REQUIRES: "table_size" is an odd (9, 11, 13, 15) power of two
43 | OUTPUT: maximal copy distance <= |input_size|
44 | OUTPUT: maximal copy distance <= BROTLI_MAX_BACKWARD_LIMIT(18) */
45 | BROTLI_INTERNAL void BrotliCompressFragmentFast(MemoryManager* m,
46 | const uint8_t* input,
47 | size_t input_size,
48 | BROTLI_BOOL is_last,
49 | int* table, size_t table_size,
50 | uint8_t cmd_depth[128],
51 | uint16_t cmd_bits[128],
52 | size_t* cmd_code_numbits,
53 | uint8_t* cmd_code,
54 | size_t* storage_ix,
55 | uint8_t* storage);
56 |
57 | #if defined(__cplusplus) || defined(c_plusplus)
58 | } /* extern "C" */
59 | #endif
60 |
61 | #endif /* BROTLI_ENC_COMPRESS_FRAGMENT_H_ */
62 |
--------------------------------------------------------------------------------
/Extra/brotli/enc/compress_fragment_two_pass.h:
--------------------------------------------------------------------------------
1 | /* Copyright 2015 Google Inc. All Rights Reserved.
2 |
3 | Distributed under MIT license.
4 | See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
5 | */
6 |
7 | /* Function for fast encoding of an input fragment, independently from the input
8 | history. This function uses two-pass processing: in the first pass we save
9 | the found backward matches and literal bytes into a buffer, and in the
10 | second pass we emit them into the bit stream using prefix codes built based
11 | on the actual command and literal byte histograms. */
12 |
13 | #ifndef BROTLI_ENC_COMPRESS_FRAGMENT_TWO_PASS_H_
14 | #define BROTLI_ENC_COMPRESS_FRAGMENT_TWO_PASS_H_
15 |
16 | #include "../common/platform.h"
17 | #include
18 | #include "./memory.h"
19 |
20 | #if defined(__cplusplus) || defined(c_plusplus)
21 | extern "C" {
22 | #endif
23 |
24 | static const size_t kCompressFragmentTwoPassBlockSize = 1 << 17;
25 |
26 | /* Compresses "input" string to the "*storage" buffer as one or more complete
27 | meta-blocks, and updates the "*storage_ix" bit position.
28 |
29 | If "is_last" is 1, emits an additional empty last meta-block.
30 |
31 | REQUIRES: "input_size" is greater than zero, or "is_last" is 1.
32 | REQUIRES: "input_size" is less or equal to maximal metablock size (1 << 24).
33 | REQUIRES: "command_buf" and "literal_buf" point to at least
34 | kCompressFragmentTwoPassBlockSize long arrays.
35 | REQUIRES: All elements in "table[0..table_size-1]" are initialized to zero.
36 | REQUIRES: "table_size" is a power of two
37 | OUTPUT: maximal copy distance <= |input_size|
38 | OUTPUT: maximal copy distance <= BROTLI_MAX_BACKWARD_LIMIT(18) */
39 | BROTLI_INTERNAL void BrotliCompressFragmentTwoPass(MemoryManager* m,
40 | const uint8_t* input,
41 | size_t input_size,
42 | BROTLI_BOOL is_last,
43 | uint32_t* command_buf,
44 | uint8_t* literal_buf,
45 | int* table,
46 | size_t table_size,
47 | size_t* storage_ix,
48 | uint8_t* storage);
49 |
50 | #if defined(__cplusplus) || defined(c_plusplus)
51 | } /* extern "C" */
52 | #endif
53 |
54 | #endif /* BROTLI_ENC_COMPRESS_FRAGMENT_TWO_PASS_H_ */
55 |
--------------------------------------------------------------------------------
/Extra/brotli/enc/dictionary_hash.h:
--------------------------------------------------------------------------------
1 | /* Copyright 2015 Google Inc. All Rights Reserved.
2 |
3 | Distributed under MIT license.
4 | See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
5 | */
6 |
7 | /* Hash table on the 4-byte prefixes of static dictionary words. */
8 |
9 | #ifndef BROTLI_ENC_DICTIONARY_HASH_H_
10 | #define BROTLI_ENC_DICTIONARY_HASH_H_
11 |
12 | #include
13 |
14 | #if defined(__cplusplus) || defined(c_plusplus)
15 | extern "C" {
16 | #endif
17 |
18 | extern const uint16_t kStaticDictionaryHashWords[32768];
19 | extern const uint8_t kStaticDictionaryHashLengths[32768];
20 |
21 | #if defined(__cplusplus) || defined(c_plusplus)
22 | } /* extern "C" */
23 | #endif
24 |
25 | #endif /* BROTLI_ENC_DICTIONARY_HASH_H_ */
26 |
--------------------------------------------------------------------------------
/Extra/brotli/enc/encoder_dict.c:
--------------------------------------------------------------------------------
1 | /* Copyright 2017 Google Inc. All Rights Reserved.
2 |
3 | Distributed under MIT license.
4 | See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
5 | */
6 |
7 | #include "./encoder_dict.h"
8 |
9 | #include "../common/dictionary.h"
10 | #include "../common/transform.h"
11 | #include "./dictionary_hash.h"
12 | #include "./hash.h"
13 |
14 | #if defined(__cplusplus) || defined(c_plusplus)
15 | extern "C" {
16 | #endif
17 |
18 | void BrotliInitEncoderDictionary(BrotliEncoderDictionary* dict) {
19 | dict->words = BrotliGetDictionary();
20 | dict->num_transforms = (uint32_t)BrotliGetTransforms()->num_transforms;
21 |
22 | dict->hash_table_words = kStaticDictionaryHashWords;
23 | dict->hash_table_lengths = kStaticDictionaryHashLengths;
24 | dict->buckets = kStaticDictionaryBuckets;
25 | dict->dict_words = kStaticDictionaryWords;
26 |
27 | dict->cutoffTransformsCount = kCutoffTransformsCount;
28 | dict->cutoffTransforms = kCutoffTransforms;
29 | }
30 |
31 | #if defined(__cplusplus) || defined(c_plusplus)
32 | } /* extern "C" */
33 | #endif
34 |
--------------------------------------------------------------------------------
/Extra/brotli/enc/encoder_dict.h:
--------------------------------------------------------------------------------
1 | /* Copyright 2017 Google Inc. All Rights Reserved.
2 |
3 | Distributed under MIT license.
4 | See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
5 | */
6 |
7 | #ifndef BROTLI_ENC_ENCODER_DICT_H_
8 | #define BROTLI_ENC_ENCODER_DICT_H_
9 |
10 | #include "../common/dictionary.h"
11 | #include "../common/platform.h"
12 | #include
13 | #include "./static_dict_lut.h"
14 |
15 | #if defined(__cplusplus) || defined(c_plusplus)
16 | extern "C" {
17 | #endif
18 |
19 | /* Dictionary data (words and transforms) for 1 possible context */
20 | typedef struct BrotliEncoderDictionary {
21 | const BrotliDictionary* words;
22 | uint32_t num_transforms;
23 |
24 | /* cut off for fast encoder */
25 | uint32_t cutoffTransformsCount;
26 | uint64_t cutoffTransforms;
27 |
28 | /* from dictionary_hash.h, for fast encoder */
29 | const uint16_t* hash_table_words;
30 | const uint8_t* hash_table_lengths;
31 |
32 | /* from static_dict_lut.h, for slow encoder */
33 | const uint16_t* buckets;
34 | const DictWord* dict_words;
35 | } BrotliEncoderDictionary;
36 |
37 | BROTLI_INTERNAL void BrotliInitEncoderDictionary(BrotliEncoderDictionary* dict);
38 |
39 | #if defined(__cplusplus) || defined(c_plusplus)
40 | } /* extern "C" */
41 | #endif
42 |
43 | #endif /* BROTLI_ENC_ENCODER_DICT_H_ */
44 |
--------------------------------------------------------------------------------
/Extra/brotli/enc/fast_log.h:
--------------------------------------------------------------------------------
1 | /* Copyright 2013 Google Inc. All Rights Reserved.
2 |
3 | Distributed under MIT license.
4 | See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
5 | */
6 |
7 | /* Utilities for fast computation of logarithms. */
8 |
9 | #ifndef BROTLI_ENC_FAST_LOG_H_
10 | #define BROTLI_ENC_FAST_LOG_H_
11 |
12 | #include
13 |
14 | #include "../common/platform.h"
15 | #include
16 |
17 | #if defined(__cplusplus) || defined(c_plusplus)
18 | extern "C" {
19 | #endif
20 |
21 | static BROTLI_INLINE uint32_t Log2FloorNonZero(size_t n) {
22 | #if defined(BROTLI_BSR32)
23 | return BROTLI_BSR32((uint32_t)n);
24 | #else
25 | uint32_t result = 0;
26 | while (n >>= 1) result++;
27 | return result;
28 | #endif
29 | }
30 |
31 | #define BROTLI_LOG2_TABLE_SIZE 256
32 |
33 | /* A lookup table for small values of log2(int) to be used in entropy
34 | computation. */
35 | BROTLI_INTERNAL extern const double kBrotliLog2Table[BROTLI_LOG2_TABLE_SIZE];
36 |
37 | /* Visual Studio 2012 and Android API levels < 18 do not have the log2()
38 | * function defined, so we use log() and a multiplication instead. */
39 | #if !defined(BROTLI_HAVE_LOG2)
40 | #if ((defined(_MSC_VER) && _MSC_VER <= 1700) || \
41 | (defined(__ANDROID_API__) && __ANDROID_API__ < 18))
42 | #define BROTLI_HAVE_LOG2 0
43 | #else
44 | #define BROTLI_HAVE_LOG2 1
45 | #endif
46 | #endif
47 |
48 | #define LOG_2_INV 1.4426950408889634
49 |
50 | /* Faster logarithm for small integers, with the property of log2(0) == 0. */
51 | static BROTLI_INLINE double FastLog2(size_t v) {
52 | if (v < BROTLI_LOG2_TABLE_SIZE) {
53 | return kBrotliLog2Table[v];
54 | }
55 | #if !(BROTLI_HAVE_LOG2)
56 | return log((double)v) * LOG_2_INV;
57 | #else
58 | return log2((double)v);
59 | #endif
60 | }
61 |
62 | #if defined(__cplusplus) || defined(c_plusplus)
63 | } /* extern "C" */
64 | #endif
65 |
66 | #endif /* BROTLI_ENC_FAST_LOG_H_ */
67 |
--------------------------------------------------------------------------------
/Extra/brotli/enc/find_match_length.h:
--------------------------------------------------------------------------------
1 | /* Copyright 2010 Google Inc. All Rights Reserved.
2 |
3 | Distributed under MIT license.
4 | See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
5 | */
6 |
7 | /* Function to find maximal matching prefixes of strings. */
8 |
9 | #ifndef BROTLI_ENC_FIND_MATCH_LENGTH_H_
10 | #define BROTLI_ENC_FIND_MATCH_LENGTH_H_
11 |
12 | #include "../common/platform.h"
13 | #include
14 |
15 | #if defined(__cplusplus) || defined(c_plusplus)
16 | extern "C" {
17 | #endif
18 |
19 | /* Separate implementation for little-endian 64-bit targets, for speed. */
20 | #if defined(BROTLI_TZCNT64) && BROTLI_64_BITS && BROTLI_LITTLE_ENDIAN
21 | static BROTLI_INLINE size_t FindMatchLengthWithLimit(const uint8_t* s1,
22 | const uint8_t* s2,
23 | size_t limit) {
24 | size_t matched = 0;
25 | size_t limit2 = (limit >> 3) + 1; /* + 1 is for pre-decrement in while */
26 | while (BROTLI_PREDICT_TRUE(--limit2)) {
27 | if (BROTLI_PREDICT_FALSE(BROTLI_UNALIGNED_LOAD64LE(s2) ==
28 | BROTLI_UNALIGNED_LOAD64LE(s1 + matched))) {
29 | s2 += 8;
30 | matched += 8;
31 | } else {
32 | uint64_t x = BROTLI_UNALIGNED_LOAD64LE(s2) ^
33 | BROTLI_UNALIGNED_LOAD64LE(s1 + matched);
34 | size_t matching_bits = (size_t)BROTLI_TZCNT64(x);
35 | matched += matching_bits >> 3;
36 | return matched;
37 | }
38 | }
39 | limit = (limit & 7) + 1; /* + 1 is for pre-decrement in while */
40 | while (--limit) {
41 | if (BROTLI_PREDICT_TRUE(s1[matched] == *s2)) {
42 | ++s2;
43 | ++matched;
44 | } else {
45 | return matched;
46 | }
47 | }
48 | return matched;
49 | }
50 | #else
51 | static BROTLI_INLINE size_t FindMatchLengthWithLimit(const uint8_t* s1,
52 | const uint8_t* s2,
53 | size_t limit) {
54 | size_t matched = 0;
55 | const uint8_t* s2_limit = s2 + limit;
56 | const uint8_t* s2_ptr = s2;
57 | /* Find out how long the match is. We loop over the data 32 bits at a
58 | time until we find a 32-bit block that doesn't match; then we find
59 | the first non-matching bit and use that to calculate the total
60 | length of the match. */
61 | while (s2_ptr <= s2_limit - 4 &&
62 | BrotliUnalignedRead32(s2_ptr) ==
63 | BrotliUnalignedRead32(s1 + matched)) {
64 | s2_ptr += 4;
65 | matched += 4;
66 | }
67 | while ((s2_ptr < s2_limit) && (s1[matched] == *s2_ptr)) {
68 | ++s2_ptr;
69 | ++matched;
70 | }
71 | return matched;
72 | }
73 | #endif
74 |
75 | #if defined(__cplusplus) || defined(c_plusplus)
76 | } /* extern "C" */
77 | #endif
78 |
79 | #endif /* BROTLI_ENC_FIND_MATCH_LENGTH_H_ */
80 |
--------------------------------------------------------------------------------
/Extra/brotli/enc/histogram.c:
--------------------------------------------------------------------------------
1 | /* Copyright 2013 Google Inc. All Rights Reserved.
2 |
3 | Distributed under MIT license.
4 | See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
5 | */
6 |
7 | /* Build per-context histograms of literals, commands and distance codes. */
8 |
9 | #include "./histogram.h"
10 |
11 | #include "../common/context.h"
12 | #include "./block_splitter.h"
13 | #include "./command.h"
14 |
15 | #if defined(__cplusplus) || defined(c_plusplus)
16 | extern "C" {
17 | #endif
18 |
19 | typedef struct BlockSplitIterator {
20 | const BlockSplit* split_; /* Not owned. */
21 | size_t idx_;
22 | size_t type_;
23 | size_t length_;
24 | } BlockSplitIterator;
25 |
26 | static void InitBlockSplitIterator(BlockSplitIterator* self,
27 | const BlockSplit* split) {
28 | self->split_ = split;
29 | self->idx_ = 0;
30 | self->type_ = 0;
31 | self->length_ = split->lengths ? split->lengths[0] : 0;
32 | }
33 |
34 | static void BlockSplitIteratorNext(BlockSplitIterator* self) {
35 | if (self->length_ == 0) {
36 | ++self->idx_;
37 | self->type_ = self->split_->types[self->idx_];
38 | self->length_ = self->split_->lengths[self->idx_];
39 | }
40 | --self->length_;
41 | }
42 |
43 | void BrotliBuildHistogramsWithContext(
44 | const Command* cmds, const size_t num_commands,
45 | const BlockSplit* literal_split, const BlockSplit* insert_and_copy_split,
46 | const BlockSplit* dist_split, const uint8_t* ringbuffer, size_t start_pos,
47 | size_t mask, uint8_t prev_byte, uint8_t prev_byte2,
48 | const ContextType* context_modes, HistogramLiteral* literal_histograms,
49 | HistogramCommand* insert_and_copy_histograms,
50 | HistogramDistance* copy_dist_histograms) {
51 | size_t pos = start_pos;
52 | BlockSplitIterator literal_it;
53 | BlockSplitIterator insert_and_copy_it;
54 | BlockSplitIterator dist_it;
55 | size_t i;
56 |
57 | InitBlockSplitIterator(&literal_it, literal_split);
58 | InitBlockSplitIterator(&insert_and_copy_it, insert_and_copy_split);
59 | InitBlockSplitIterator(&dist_it, dist_split);
60 | for (i = 0; i < num_commands; ++i) {
61 | const Command* cmd = &cmds[i];
62 | size_t j;
63 | BlockSplitIteratorNext(&insert_and_copy_it);
64 | HistogramAddCommand(&insert_and_copy_histograms[insert_and_copy_it.type_],
65 | cmd->cmd_prefix_);
66 | /* TODO: unwrap iterator blocks. */
67 | for (j = cmd->insert_len_; j != 0; --j) {
68 | size_t context;
69 | BlockSplitIteratorNext(&literal_it);
70 | context = literal_it.type_;
71 | if (context_modes) {
72 | ContextLut lut = BROTLI_CONTEXT_LUT(context_modes[context]);
73 | context = (context << BROTLI_LITERAL_CONTEXT_BITS) +
74 | BROTLI_CONTEXT(prev_byte, prev_byte2, lut);
75 | }
76 | HistogramAddLiteral(&literal_histograms[context],
77 | ringbuffer[pos & mask]);
78 | prev_byte2 = prev_byte;
79 | prev_byte = ringbuffer[pos & mask];
80 | ++pos;
81 | }
82 | pos += CommandCopyLen(cmd);
83 | if (CommandCopyLen(cmd)) {
84 | prev_byte2 = ringbuffer[(pos - 2) & mask];
85 | prev_byte = ringbuffer[(pos - 1) & mask];
86 | if (cmd->cmd_prefix_ >= 128) {
87 | size_t context;
88 | BlockSplitIteratorNext(&dist_it);
89 | context = (dist_it.type_ << BROTLI_DISTANCE_CONTEXT_BITS) +
90 | CommandDistanceContext(cmd);
91 | HistogramAddDistance(©_dist_histograms[context],
92 | cmd->dist_prefix_ & 0x3FF);
93 | }
94 | }
95 | }
96 | }
97 |
98 | #if defined(__cplusplus) || defined(c_plusplus)
99 | } /* extern "C" */
100 | #endif
101 |
--------------------------------------------------------------------------------
/Extra/brotli/enc/histogram.h:
--------------------------------------------------------------------------------
1 | /* Copyright 2013 Google Inc. All Rights Reserved.
2 |
3 | Distributed under MIT license.
4 | See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
5 | */
6 |
7 | /* Models the histograms of literals, commands and distance codes. */
8 |
9 | #ifndef BROTLI_ENC_HISTOGRAM_H_
10 | #define BROTLI_ENC_HISTOGRAM_H_
11 |
12 | #include /* memset */
13 |
14 | #include "../common/constants.h"
15 | #include "../common/context.h"
16 | #include "../common/platform.h"
17 | #include
18 | #include "./block_splitter.h"
19 | #include "./command.h"
20 |
21 | #if defined(__cplusplus) || defined(c_plusplus)
22 | extern "C" {
23 | #endif
24 |
25 | /* The distance symbols effectively used by "Large Window Brotli" (32-bit). */
26 | #define BROTLI_NUM_HISTOGRAM_DISTANCE_SYMBOLS 544
27 |
28 | #define FN(X) X ## Literal
29 | #define DATA_SIZE BROTLI_NUM_LITERAL_SYMBOLS
30 | #define DataType uint8_t
31 | #include "./histogram_inc.h" /* NOLINT(build/include) */
32 | #undef DataType
33 | #undef DATA_SIZE
34 | #undef FN
35 |
36 | #define FN(X) X ## Command
37 | #define DataType uint16_t
38 | #define DATA_SIZE BROTLI_NUM_COMMAND_SYMBOLS
39 | #include "./histogram_inc.h" /* NOLINT(build/include) */
40 | #undef DATA_SIZE
41 | #undef FN
42 |
43 | #define FN(X) X ## Distance
44 | #define DATA_SIZE BROTLI_NUM_HISTOGRAM_DISTANCE_SYMBOLS
45 | #include "./histogram_inc.h" /* NOLINT(build/include) */
46 | #undef DataType
47 | #undef DATA_SIZE
48 | #undef FN
49 |
50 | BROTLI_INTERNAL void BrotliBuildHistogramsWithContext(
51 | const Command* cmds, const size_t num_commands,
52 | const BlockSplit* literal_split, const BlockSplit* insert_and_copy_split,
53 | const BlockSplit* dist_split, const uint8_t* ringbuffer, size_t pos,
54 | size_t mask, uint8_t prev_byte, uint8_t prev_byte2,
55 | const ContextType* context_modes, HistogramLiteral* literal_histograms,
56 | HistogramCommand* insert_and_copy_histograms,
57 | HistogramDistance* copy_dist_histograms);
58 |
59 | #if defined(__cplusplus) || defined(c_plusplus)
60 | } /* extern "C" */
61 | #endif
62 |
63 | #endif /* BROTLI_ENC_HISTOGRAM_H_ */
64 |
--------------------------------------------------------------------------------
/Extra/brotli/enc/histogram_inc.h:
--------------------------------------------------------------------------------
1 | /* NOLINT(build/header_guard) */
2 | /* Copyright 2013 Google Inc. All Rights Reserved.
3 |
4 | Distributed under MIT license.
5 | See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
6 | */
7 |
8 | /* template parameters: Histogram, DATA_SIZE, DataType */
9 |
10 | /* A simple container for histograms of data in blocks. */
11 |
12 | typedef struct FN(Histogram) {
13 | uint32_t data_[DATA_SIZE];
14 | size_t total_count_;
15 | double bit_cost_;
16 | } FN(Histogram);
17 |
18 | static BROTLI_INLINE void FN(HistogramClear)(FN(Histogram)* self) {
19 | memset(self->data_, 0, sizeof(self->data_));
20 | self->total_count_ = 0;
21 | self->bit_cost_ = HUGE_VAL;
22 | }
23 |
24 | static BROTLI_INLINE void FN(ClearHistograms)(
25 | FN(Histogram)* array, size_t length) {
26 | size_t i;
27 | for (i = 0; i < length; ++i) FN(HistogramClear)(array + i);
28 | }
29 |
30 | static BROTLI_INLINE void FN(HistogramAdd)(FN(Histogram)* self, size_t val) {
31 | ++self->data_[val];
32 | ++self->total_count_;
33 | }
34 |
35 | static BROTLI_INLINE void FN(HistogramAddVector)(FN(Histogram)* self,
36 | const DataType* p, size_t n) {
37 | self->total_count_ += n;
38 | n += 1;
39 | while (--n) ++self->data_[*p++];
40 | }
41 |
42 | static BROTLI_INLINE void FN(HistogramAddHistogram)(FN(Histogram)* self,
43 | const FN(Histogram)* v) {
44 | size_t i;
45 | self->total_count_ += v->total_count_;
46 | for (i = 0; i < DATA_SIZE; ++i) {
47 | self->data_[i] += v->data_[i];
48 | }
49 | }
50 |
51 | static BROTLI_INLINE size_t FN(HistogramDataSize)(void) { return DATA_SIZE; }
52 |
--------------------------------------------------------------------------------
/Extra/brotli/enc/literal_cost.h:
--------------------------------------------------------------------------------
1 | /* Copyright 2013 Google Inc. All Rights Reserved.
2 |
3 | Distributed under MIT license.
4 | See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
5 | */
6 |
7 | /* Literal cost model to allow backward reference replacement to be efficient.
8 | */
9 |
10 | #ifndef BROTLI_ENC_LITERAL_COST_H_
11 | #define BROTLI_ENC_LITERAL_COST_H_
12 |
13 | #include "../common/platform.h"
14 | #include
15 |
16 | #if defined(__cplusplus) || defined(c_plusplus)
17 | extern "C" {
18 | #endif
19 |
20 | /* Estimates how many bits the literals in the interval [pos, pos + len) in the
21 | ring-buffer (data, mask) will take entropy coded and writes these estimates
22 | to the cost[0..len) array. */
23 | BROTLI_INTERNAL void BrotliEstimateBitCostsForLiterals(
24 | size_t pos, size_t len, size_t mask, const uint8_t* data, float* cost);
25 |
26 | #if defined(__cplusplus) || defined(c_plusplus)
27 | } /* extern "C" */
28 | #endif
29 |
30 | #endif /* BROTLI_ENC_LITERAL_COST_H_ */
31 |
--------------------------------------------------------------------------------
/Extra/brotli/enc/memory.h:
--------------------------------------------------------------------------------
1 | /* Copyright 2016 Google Inc. All Rights Reserved.
2 |
3 | Distributed under MIT license.
4 | See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
5 | */
6 |
7 | /* Macros for memory management. */
8 |
9 | #ifndef BROTLI_ENC_MEMORY_H_
10 | #define BROTLI_ENC_MEMORY_H_
11 |
12 | #include /* memcpy */
13 |
14 | #include "../common/platform.h"
15 | #include
16 |
17 | #if defined(__cplusplus) || defined(c_plusplus)
18 | extern "C" {
19 | #endif
20 |
21 | #if !defined(BROTLI_ENCODER_CLEANUP_ON_OOM) && \
22 | !defined(BROTLI_ENCODER_EXIT_ON_OOM)
23 | #define BROTLI_ENCODER_EXIT_ON_OOM
24 | #endif
25 |
26 | typedef struct MemoryManager {
27 | brotli_alloc_func alloc_func;
28 | brotli_free_func free_func;
29 | void* opaque;
30 | #if !defined(BROTLI_ENCODER_EXIT_ON_OOM)
31 | BROTLI_BOOL is_oom;
32 | size_t perm_allocated;
33 | size_t new_allocated;
34 | size_t new_freed;
35 | void* pointers[256];
36 | #endif /* BROTLI_ENCODER_EXIT_ON_OOM */
37 | } MemoryManager;
38 |
39 | BROTLI_INTERNAL void BrotliInitMemoryManager(
40 | MemoryManager* m, brotli_alloc_func alloc_func, brotli_free_func free_func,
41 | void* opaque);
42 |
43 | BROTLI_INTERNAL void* BrotliAllocate(MemoryManager* m, size_t n);
44 | #define BROTLI_ALLOC(M, T, N) \
45 | ((N) > 0 ? ((T*)BrotliAllocate((M), (N) * sizeof(T))) : NULL)
46 |
47 | BROTLI_INTERNAL void BrotliFree(MemoryManager* m, void* p);
48 | #define BROTLI_FREE(M, P) { \
49 | BrotliFree((M), (P)); \
50 | P = NULL; \
51 | }
52 |
53 | #if defined(BROTLI_ENCODER_EXIT_ON_OOM)
54 | #define BROTLI_IS_OOM(M) (!!0)
55 | #else /* BROTLI_ENCODER_EXIT_ON_OOM */
56 | #define BROTLI_IS_OOM(M) (!!(M)->is_oom)
57 | #endif /* BROTLI_ENCODER_EXIT_ON_OOM */
58 |
59 | /*
60 | BROTLI_IS_NULL is a fake check, BROTLI_IS_OOM does the heavy lifting.
61 | The only purpose of it is to explain static analyzers the state of things.
62 | NB: use ONLY together with BROTLI_IS_OOM
63 | AND ONLY for allocations in the current scope.
64 | */
65 | #if defined(__clang_analyzer__) && !defined(BROTLI_ENCODER_EXIT_ON_OOM)
66 | #define BROTLI_IS_NULL(A) ((A) == nullptr)
67 | #else /* defined(__clang_analyzer__) */
68 | #define BROTLI_IS_NULL(A) (!!0)
69 | #endif /* defined(__clang_analyzer__) */
70 |
71 | BROTLI_INTERNAL void BrotliWipeOutMemoryManager(MemoryManager* m);
72 |
73 | /*
74 | Dynamically grows array capacity to at least the requested size
75 | M: MemoryManager
76 | T: data type
77 | A: array
78 | C: capacity
79 | R: requested size
80 | */
81 | #define BROTLI_ENSURE_CAPACITY(M, T, A, C, R) { \
82 | if (C < (R)) { \
83 | size_t _new_size = (C == 0) ? (R) : C; \
84 | T* new_array; \
85 | while (_new_size < (R)) _new_size *= 2; \
86 | new_array = BROTLI_ALLOC((M), T, _new_size); \
87 | if (!BROTLI_IS_OOM(M) && !BROTLI_IS_NULL(new_array) && C != 0) \
88 | memcpy(new_array, A, C * sizeof(T)); \
89 | BROTLI_FREE((M), A); \
90 | A = new_array; \
91 | C = _new_size; \
92 | } \
93 | }
94 |
95 | /*
96 | Appends value and dynamically grows array capacity when needed
97 | M: MemoryManager
98 | T: data type
99 | A: array
100 | C: array capacity
101 | S: array size
102 | V: value to append
103 | */
104 | #define BROTLI_ENSURE_CAPACITY_APPEND(M, T, A, C, S, V) { \
105 | (S)++; \
106 | BROTLI_ENSURE_CAPACITY(M, T, A, C, S); \
107 | A[(S) - 1] = (V); \
108 | }
109 |
110 | #if defined(__cplusplus) || defined(c_plusplus)
111 | } /* extern "C" */
112 | #endif
113 |
114 | #endif /* BROTLI_ENC_MEMORY_H_ */
115 |
--------------------------------------------------------------------------------
/Extra/brotli/enc/metablock.h:
--------------------------------------------------------------------------------
1 | /* Copyright 2015 Google Inc. All Rights Reserved.
2 |
3 | Distributed under MIT license.
4 | See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
5 | */
6 |
7 | /* Algorithms for distributing the literals and commands of a metablock between
8 | block types and contexts. */
9 |
10 | #ifndef BROTLI_ENC_METABLOCK_H_
11 | #define BROTLI_ENC_METABLOCK_H_
12 |
13 | #include "../common/context.h"
14 | #include "../common/platform.h"
15 | #include
16 | #include "./block_splitter.h"
17 | #include "./command.h"
18 | #include "./histogram.h"
19 | #include "./memory.h"
20 | #include "./quality.h"
21 |
22 | #if defined(__cplusplus) || defined(c_plusplus)
23 | extern "C" {
24 | #endif
25 |
26 | typedef struct MetaBlockSplit {
27 | BlockSplit literal_split;
28 | BlockSplit command_split;
29 | BlockSplit distance_split;
30 | uint32_t* literal_context_map;
31 | size_t literal_context_map_size;
32 | uint32_t* distance_context_map;
33 | size_t distance_context_map_size;
34 | HistogramLiteral* literal_histograms;
35 | size_t literal_histograms_size;
36 | HistogramCommand* command_histograms;
37 | size_t command_histograms_size;
38 | HistogramDistance* distance_histograms;
39 | size_t distance_histograms_size;
40 | } MetaBlockSplit;
41 |
42 | static BROTLI_INLINE void InitMetaBlockSplit(MetaBlockSplit* mb) {
43 | BrotliInitBlockSplit(&mb->literal_split);
44 | BrotliInitBlockSplit(&mb->command_split);
45 | BrotliInitBlockSplit(&mb->distance_split);
46 | mb->literal_context_map = 0;
47 | mb->literal_context_map_size = 0;
48 | mb->distance_context_map = 0;
49 | mb->distance_context_map_size = 0;
50 | mb->literal_histograms = 0;
51 | mb->literal_histograms_size = 0;
52 | mb->command_histograms = 0;
53 | mb->command_histograms_size = 0;
54 | mb->distance_histograms = 0;
55 | mb->distance_histograms_size = 0;
56 | }
57 |
58 | static BROTLI_INLINE void DestroyMetaBlockSplit(
59 | MemoryManager* m, MetaBlockSplit* mb) {
60 | BrotliDestroyBlockSplit(m, &mb->literal_split);
61 | BrotliDestroyBlockSplit(m, &mb->command_split);
62 | BrotliDestroyBlockSplit(m, &mb->distance_split);
63 | BROTLI_FREE(m, mb->literal_context_map);
64 | BROTLI_FREE(m, mb->distance_context_map);
65 | BROTLI_FREE(m, mb->literal_histograms);
66 | BROTLI_FREE(m, mb->command_histograms);
67 | BROTLI_FREE(m, mb->distance_histograms);
68 | }
69 |
70 | /* Uses the slow shortest-path block splitter and does context clustering.
71 | The distance parameters are dynamically selected based on the commands
72 | which get recomputed under the new distance parameters. The new distance
73 | parameters are stored into *params. */
74 | BROTLI_INTERNAL void BrotliBuildMetaBlock(MemoryManager* m,
75 | const uint8_t* ringbuffer,
76 | const size_t pos,
77 | const size_t mask,
78 | BrotliEncoderParams* params,
79 | uint8_t prev_byte,
80 | uint8_t prev_byte2,
81 | Command* cmds,
82 | size_t num_commands,
83 | ContextType literal_context_mode,
84 | MetaBlockSplit* mb);
85 |
86 | /* Uses a fast greedy block splitter that tries to merge current block with the
87 | last or the second last block and uses a static context clustering which
88 | is the same for all block types. */
89 | BROTLI_INTERNAL void BrotliBuildMetaBlockGreedy(
90 | MemoryManager* m, const uint8_t* ringbuffer, size_t pos, size_t mask,
91 | uint8_t prev_byte, uint8_t prev_byte2, ContextLut literal_context_lut,
92 | size_t num_contexts, const uint32_t* static_context_map,
93 | const Command* commands, size_t n_commands, MetaBlockSplit* mb);
94 |
95 | BROTLI_INTERNAL void BrotliOptimizeHistograms(uint32_t num_distance_codes,
96 | MetaBlockSplit* mb);
97 |
98 | BROTLI_INTERNAL void BrotliInitDistanceParams(BrotliEncoderParams* params,
99 | uint32_t npostfix, uint32_t ndirect);
100 |
101 | #if defined(__cplusplus) || defined(c_plusplus)
102 | } /* extern "C" */
103 | #endif
104 |
105 | #endif /* BROTLI_ENC_METABLOCK_H_ */
106 |
--------------------------------------------------------------------------------
/Extra/brotli/enc/params.h:
--------------------------------------------------------------------------------
1 | /* Copyright 2017 Google Inc. All Rights Reserved.
2 |
3 | Distributed under MIT license.
4 | See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
5 | */
6 |
7 | /* Parameters for the Brotli encoder with chosen quality levels. */
8 |
9 | #ifndef BROTLI_ENC_PARAMS_H_
10 | #define BROTLI_ENC_PARAMS_H_
11 |
12 | #include
13 | #include "./encoder_dict.h"
14 |
15 | typedef struct BrotliHasherParams {
16 | int type;
17 | int bucket_bits;
18 | int block_bits;
19 | int hash_len;
20 | int num_last_distances_to_check;
21 | } BrotliHasherParams;
22 |
23 | typedef struct BrotliDistanceParams {
24 | uint32_t distance_postfix_bits;
25 | uint32_t num_direct_distance_codes;
26 | uint32_t alphabet_size_max;
27 | uint32_t alphabet_size_limit;
28 | size_t max_distance;
29 | } BrotliDistanceParams;
30 |
31 | /* Encoding parameters */
32 | typedef struct BrotliEncoderParams {
33 | BrotliEncoderMode mode;
34 | int quality;
35 | int lgwin;
36 | int lgblock;
37 | size_t stream_offset;
38 | size_t size_hint;
39 | BROTLI_BOOL disable_literal_context_modeling;
40 | BROTLI_BOOL large_window;
41 | BrotliHasherParams hasher;
42 | BrotliDistanceParams dist;
43 | BrotliEncoderDictionary dictionary;
44 | } BrotliEncoderParams;
45 |
46 | #endif /* BROTLI_ENC_PARAMS_H_ */
47 |
--------------------------------------------------------------------------------
/Extra/brotli/enc/prefix.h:
--------------------------------------------------------------------------------
1 | /* Copyright 2013 Google Inc. All Rights Reserved.
2 |
3 | Distributed under MIT license.
4 | See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
5 | */
6 |
7 | /* Functions for encoding of integers into prefix codes the amount of extra
8 | bits, and the actual values of the extra bits. */
9 |
10 | #ifndef BROTLI_ENC_PREFIX_H_
11 | #define BROTLI_ENC_PREFIX_H_
12 |
13 | #include "../common/constants.h"
14 | #include "../common/platform.h"
15 | #include
16 | #include "./fast_log.h"
17 |
18 | #if defined(__cplusplus) || defined(c_plusplus)
19 | extern "C" {
20 | #endif
21 |
22 | /* Here distance_code is an intermediate code, i.e. one of the special codes or
23 | the actual distance increased by BROTLI_NUM_DISTANCE_SHORT_CODES - 1. */
24 | static BROTLI_INLINE void PrefixEncodeCopyDistance(size_t distance_code,
25 | size_t num_direct_codes,
26 | size_t postfix_bits,
27 | uint16_t* code,
28 | uint32_t* extra_bits) {
29 | if (distance_code < BROTLI_NUM_DISTANCE_SHORT_CODES + num_direct_codes) {
30 | *code = (uint16_t)distance_code;
31 | *extra_bits = 0;
32 | return;
33 | } else {
34 | size_t dist = ((size_t)1 << (postfix_bits + 2u)) +
35 | (distance_code - BROTLI_NUM_DISTANCE_SHORT_CODES - num_direct_codes);
36 | size_t bucket = Log2FloorNonZero(dist) - 1;
37 | size_t postfix_mask = (1u << postfix_bits) - 1;
38 | size_t postfix = dist & postfix_mask;
39 | size_t prefix = (dist >> bucket) & 1;
40 | size_t offset = (2 + prefix) << bucket;
41 | size_t nbits = bucket - postfix_bits;
42 | *code = (uint16_t)((nbits << 10) |
43 | (BROTLI_NUM_DISTANCE_SHORT_CODES + num_direct_codes +
44 | ((2 * (nbits - 1) + prefix) << postfix_bits) + postfix));
45 | *extra_bits = (uint32_t)((dist - offset) >> postfix_bits);
46 | }
47 | }
48 |
49 | #if defined(__cplusplus) || defined(c_plusplus)
50 | } /* extern "C" */
51 | #endif
52 |
53 | #endif /* BROTLI_ENC_PREFIX_H_ */
54 |
--------------------------------------------------------------------------------
/Extra/brotli/enc/static_dict.h:
--------------------------------------------------------------------------------
1 | /* Copyright 2013 Google Inc. All Rights Reserved.
2 |
3 | Distributed under MIT license.
4 | See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
5 | */
6 |
7 | /* Class to model the static dictionary. */
8 |
9 | #ifndef BROTLI_ENC_STATIC_DICT_H_
10 | #define BROTLI_ENC_STATIC_DICT_H_
11 |
12 | #include "../common/dictionary.h"
13 | #include "../common/platform.h"
14 | #include
15 | #include "./encoder_dict.h"
16 |
17 | #if defined(__cplusplus) || defined(c_plusplus)
18 | extern "C" {
19 | #endif
20 |
21 | #define BROTLI_MAX_STATIC_DICTIONARY_MATCH_LEN 37
22 | static const uint32_t kInvalidMatch = 0xFFFFFFF;
23 |
24 | /* Matches data against static dictionary words, and for each length l,
25 | for which a match is found, updates matches[l] to be the minimum possible
26 | (distance << 5) + len_code.
27 | Returns 1 if matches have been found, otherwise 0.
28 | Prerequisites:
29 | matches array is at least BROTLI_MAX_STATIC_DICTIONARY_MATCH_LEN + 1 long
30 | all elements are initialized to kInvalidMatch */
31 | BROTLI_INTERNAL BROTLI_BOOL BrotliFindAllStaticDictionaryMatches(
32 | const BrotliEncoderDictionary* dictionary,
33 | const uint8_t* data, size_t min_length, size_t max_length,
34 | uint32_t* matches);
35 |
36 | #if defined(__cplusplus) || defined(c_plusplus)
37 | } /* extern "C" */
38 | #endif
39 |
40 | #endif /* BROTLI_ENC_STATIC_DICT_H_ */
41 |
--------------------------------------------------------------------------------
/Extra/brotli/enc/utf8_util.c:
--------------------------------------------------------------------------------
1 | /* Copyright 2013 Google Inc. All Rights Reserved.
2 |
3 | Distributed under MIT license.
4 | See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
5 | */
6 |
7 | /* Heuristics for deciding about the UTF8-ness of strings. */
8 |
9 | #include "./utf8_util.h"
10 |
11 | #include
12 |
13 | #if defined(__cplusplus) || defined(c_plusplus)
14 | extern "C" {
15 | #endif
16 |
17 | static size_t BrotliParseAsUTF8(
18 | int* symbol, const uint8_t* input, size_t size) {
19 | /* ASCII */
20 | if ((input[0] & 0x80) == 0) {
21 | *symbol = input[0];
22 | if (*symbol > 0) {
23 | return 1;
24 | }
25 | }
26 | /* 2-byte UTF8 */
27 | if (size > 1u &&
28 | (input[0] & 0xE0) == 0xC0 &&
29 | (input[1] & 0xC0) == 0x80) {
30 | *symbol = (((input[0] & 0x1F) << 6) |
31 | (input[1] & 0x3F));
32 | if (*symbol > 0x7F) {
33 | return 2;
34 | }
35 | }
36 | /* 3-byte UFT8 */
37 | if (size > 2u &&
38 | (input[0] & 0xF0) == 0xE0 &&
39 | (input[1] & 0xC0) == 0x80 &&
40 | (input[2] & 0xC0) == 0x80) {
41 | *symbol = (((input[0] & 0x0F) << 12) |
42 | ((input[1] & 0x3F) << 6) |
43 | (input[2] & 0x3F));
44 | if (*symbol > 0x7FF) {
45 | return 3;
46 | }
47 | }
48 | /* 4-byte UFT8 */
49 | if (size > 3u &&
50 | (input[0] & 0xF8) == 0xF0 &&
51 | (input[1] & 0xC0) == 0x80 &&
52 | (input[2] & 0xC0) == 0x80 &&
53 | (input[3] & 0xC0) == 0x80) {
54 | *symbol = (((input[0] & 0x07) << 18) |
55 | ((input[1] & 0x3F) << 12) |
56 | ((input[2] & 0x3F) << 6) |
57 | (input[3] & 0x3F));
58 | if (*symbol > 0xFFFF && *symbol <= 0x10FFFF) {
59 | return 4;
60 | }
61 | }
62 | /* Not UTF8, emit a special symbol above the UTF8-code space */
63 | *symbol = 0x110000 | input[0];
64 | return 1;
65 | }
66 |
67 | /* Returns 1 if at least min_fraction of the data is UTF8-encoded.*/
68 | BROTLI_BOOL BrotliIsMostlyUTF8(
69 | const uint8_t* data, const size_t pos, const size_t mask,
70 | const size_t length, const double min_fraction) {
71 | size_t size_utf8 = 0;
72 | size_t i = 0;
73 | while (i < length) {
74 | int symbol;
75 | size_t bytes_read =
76 | BrotliParseAsUTF8(&symbol, &data[(pos + i) & mask], length - i);
77 | i += bytes_read;
78 | if (symbol < 0x110000) size_utf8 += bytes_read;
79 | }
80 | return TO_BROTLI_BOOL((double)size_utf8 > min_fraction * (double)length);
81 | }
82 |
83 | #if defined(__cplusplus) || defined(c_plusplus)
84 | } /* extern "C" */
85 | #endif
86 |
--------------------------------------------------------------------------------
/Extra/brotli/enc/utf8_util.h:
--------------------------------------------------------------------------------
1 | /* Copyright 2013 Google Inc. All Rights Reserved.
2 |
3 | Distributed under MIT license.
4 | See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
5 | */
6 |
7 | /* Heuristics for deciding about the UTF8-ness of strings. */
8 |
9 | #ifndef BROTLI_ENC_UTF8_UTIL_H_
10 | #define BROTLI_ENC_UTF8_UTIL_H_
11 |
12 | #include "../common/platform.h"
13 | #include
14 |
15 | #if defined(__cplusplus) || defined(c_plusplus)
16 | extern "C" {
17 | #endif
18 |
19 | static const double kMinUTF8Ratio = 0.75;
20 |
21 | /* Returns 1 if at least min_fraction of the bytes between pos and
22 | pos + length in the (data, mask) ring-buffer is UTF8-encoded, otherwise
23 | returns 0. */
24 | BROTLI_INTERNAL BROTLI_BOOL BrotliIsMostlyUTF8(
25 | const uint8_t* data, const size_t pos, const size_t mask,
26 | const size_t length, const double min_fraction);
27 |
28 | #if defined(__cplusplus) || defined(c_plusplus)
29 | } /* extern "C" */
30 | #endif
31 |
32 | #endif /* BROTLI_ENC_UTF8_UTIL_H_ */
33 |
--------------------------------------------------------------------------------
/Extra/brotli/enc/write_bits.h:
--------------------------------------------------------------------------------
1 | /* Copyright 2010 Google Inc. All Rights Reserved.
2 |
3 | Distributed under MIT license.
4 | See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
5 | */
6 |
7 | /* Write bits into a byte array. */
8 |
9 | #ifndef BROTLI_ENC_WRITE_BITS_H_
10 | #define BROTLI_ENC_WRITE_BITS_H_
11 |
12 | #include "../common/platform.h"
13 | #include
14 |
15 | #if defined(__cplusplus) || defined(c_plusplus)
16 | extern "C" {
17 | #endif
18 |
19 | /* This function writes bits into bytes in increasing addresses, and within
20 | a byte least-significant-bit first.
21 |
22 | The function can write up to 56 bits in one go with WriteBits
23 | Example: let's assume that 3 bits (Rs below) have been written already:
24 |
25 | BYTE-0 BYTE+1 BYTE+2
26 |
27 | 0000 0RRR 0000 0000 0000 0000
28 |
29 | Now, we could write 5 or less bits in MSB by just shifting by 3
30 | and OR'ing to BYTE-0.
31 |
32 | For n bits, we take the last 5 bits, OR that with high bits in BYTE-0,
33 | and locate the rest in BYTE+1, BYTE+2, etc. */
34 | static BROTLI_INLINE void BrotliWriteBits(size_t n_bits,
35 | uint64_t bits,
36 | size_t* BROTLI_RESTRICT pos,
37 | uint8_t* BROTLI_RESTRICT array) {
38 | BROTLI_LOG(("WriteBits %2d 0x%08x%08x %10d\n", (int)n_bits,
39 | (uint32_t)(bits >> 32), (uint32_t)(bits & 0xFFFFFFFF),
40 | (int)*pos));
41 | BROTLI_DCHECK((bits >> n_bits) == 0);
42 | BROTLI_DCHECK(n_bits <= 56);
43 | #if defined(BROTLI_LITTLE_ENDIAN)
44 | /* This branch of the code can write up to 56 bits at a time,
45 | 7 bits are lost by being perhaps already in *p and at least
46 | 1 bit is needed to initialize the bit-stream ahead (i.e. if 7
47 | bits are in *p and we write 57 bits, then the next write will
48 | access a byte that was never initialized). */
49 | {
50 | uint8_t* p = &array[*pos >> 3];
51 | uint64_t v = (uint64_t)(*p); /* Zero-extend 8 to 64 bits. */
52 | v |= bits << (*pos & 7);
53 | BROTLI_UNALIGNED_STORE64LE(p, v); /* Set some bits. */
54 | *pos += n_bits;
55 | }
56 | #else
57 | /* implicit & 0xFF is assumed for uint8_t arithmetics */
58 | {
59 | uint8_t* array_pos = &array[*pos >> 3];
60 | const size_t bits_reserved_in_first_byte = (*pos & 7);
61 | size_t bits_left_to_write;
62 | bits <<= bits_reserved_in_first_byte;
63 | *array_pos++ |= (uint8_t)bits;
64 | for (bits_left_to_write = n_bits + bits_reserved_in_first_byte;
65 | bits_left_to_write >= 9;
66 | bits_left_to_write -= 8) {
67 | bits >>= 8;
68 | *array_pos++ = (uint8_t)bits;
69 | }
70 | *array_pos = 0;
71 | *pos += n_bits;
72 | }
73 | #endif
74 | }
75 |
76 | static BROTLI_INLINE void BrotliWriteBitsPrepareStorage(
77 | size_t pos, uint8_t* array) {
78 | BROTLI_LOG(("WriteBitsPrepareStorage %10d\n", (int)pos));
79 | BROTLI_DCHECK((pos & 7) == 0);
80 | array[pos >> 3] = 0;
81 | }
82 |
83 | #if defined(__cplusplus) || defined(c_plusplus)
84 | } /* extern "C" */
85 | #endif
86 |
87 | #endif /* BROTLI_ENC_WRITE_BITS_H_ */
88 |
--------------------------------------------------------------------------------
/Extra/brotli/include/brotli/types.h:
--------------------------------------------------------------------------------
1 | /* Copyright 2013 Google Inc. All Rights Reserved.
2 |
3 | Distributed under MIT license.
4 | See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
5 | */
6 |
7 | /**
8 | * @file
9 | * Common types used in decoder and encoder API.
10 | */
11 |
12 | #ifndef BROTLI_COMMON_TYPES_H_
13 | #define BROTLI_COMMON_TYPES_H_
14 |
15 | #include /* for size_t */
16 |
17 | #if defined(_MSC_VER) && (_MSC_VER < 1600)
18 | typedef __int8 int8_t;
19 | typedef unsigned __int8 uint8_t;
20 | typedef __int16 int16_t;
21 | typedef unsigned __int16 uint16_t;
22 | typedef __int32 int32_t;
23 | typedef unsigned __int32 uint32_t;
24 | typedef unsigned __int64 uint64_t;
25 | typedef __int64 int64_t;
26 | #else
27 | #include
28 | #endif /* defined(_MSC_VER) && (_MSC_VER < 1600) */
29 |
30 | /**
31 | * A portable @c bool replacement.
32 | *
33 | * ::BROTLI_BOOL is a "documentation" type: actually it is @c int, but in API it
34 | * denotes a type, whose only values are ::BROTLI_TRUE and ::BROTLI_FALSE.
35 | *
36 | * ::BROTLI_BOOL values passed to Brotli should either be ::BROTLI_TRUE or
37 | * ::BROTLI_FALSE, or be a result of ::TO_BROTLI_BOOL macros.
38 | *
39 | * ::BROTLI_BOOL values returned by Brotli should not be tested for equality
40 | * with @c true, @c false, ::BROTLI_TRUE, ::BROTLI_FALSE, but rather should be
41 | * evaluated, for example: @code{.cpp}
42 | * if (SomeBrotliFunction(encoder, BROTLI_TRUE) &&
43 | * !OtherBrotliFunction(decoder, BROTLI_FALSE)) {
44 | * bool x = !!YetAnotherBrotliFunction(encoder, TO_BROLTI_BOOL(2 * 2 == 4));
45 | * DoSomething(x);
46 | * }
47 | * @endcode
48 | */
49 | #define BROTLI_BOOL int
50 | /** Portable @c true replacement. */
51 | #define BROTLI_TRUE 1
52 | /** Portable @c false replacement. */
53 | #define BROTLI_FALSE 0
54 | /** @c bool to ::BROTLI_BOOL conversion macros. */
55 | #define TO_BROTLI_BOOL(X) (!!(X) ? BROTLI_TRUE : BROTLI_FALSE)
56 |
57 | #define BROTLI_MAKE_UINT64_T(high, low) ((((uint64_t)(high)) << 32) | low)
58 |
59 | #define BROTLI_UINT32_MAX (~((uint32_t)0))
60 | #define BROTLI_SIZE_MAX (~((size_t)0))
61 |
62 | /**
63 | * Allocating function pointer type.
64 | *
65 | * @param opaque custom memory manager handle provided by client
66 | * @param size requested memory region size; can not be @c 0
67 | * @returns @c 0 in the case of failure
68 | * @returns a valid pointer to a memory region of at least @p size bytes
69 | * long otherwise
70 | */
71 | typedef void* (*brotli_alloc_func)(void* opaque, size_t size);
72 |
73 | /**
74 | * Deallocating function pointer type.
75 | *
76 | * This function @b SHOULD do nothing if @p address is @c 0.
77 | *
78 | * @param opaque custom memory manager handle provided by client
79 | * @param address memory region pointer returned by ::brotli_alloc_func, or @c 0
80 | */
81 | typedef void (*brotli_free_func)(void* opaque, void* address);
82 |
83 | #endif /* BROTLI_COMMON_TYPES_H_ */
84 |
--------------------------------------------------------------------------------
/Extra/zstd/common/debug.c:
--------------------------------------------------------------------------------
1 | /* ******************************************************************
2 | * debug
3 | * Part of FSE library
4 | * Copyright (c) Yann Collet, Facebook, Inc.
5 | *
6 | * You can contact the author at :
7 | * - Source repository : https://github.com/Cyan4973/FiniteStateEntropy
8 | *
9 | * This source code is licensed under both the BSD-style license (found in the
10 | * LICENSE file in the root directory of this source tree) and the GPLv2 (found
11 | * in the COPYING file in the root directory of this source tree).
12 | * You may select, at your option, one of the above-listed licenses.
13 | ****************************************************************** */
14 |
15 |
16 | /*
17 | * This module only hosts one global variable
18 | * which can be used to dynamically influence the verbosity of traces,
19 | * such as DEBUGLOG and RAWLOG
20 | */
21 |
22 | #include "debug.h"
23 |
24 | int g_debuglevel = DEBUGLEVEL;
25 |
--------------------------------------------------------------------------------
/Extra/zstd/common/debug.h:
--------------------------------------------------------------------------------
1 | /* ******************************************************************
2 | * debug
3 | * Part of FSE library
4 | * Copyright (c) Yann Collet, Facebook, Inc.
5 | *
6 | * You can contact the author at :
7 | * - Source repository : https://github.com/Cyan4973/FiniteStateEntropy
8 | *
9 | * This source code is licensed under both the BSD-style license (found in the
10 | * LICENSE file in the root directory of this source tree) and the GPLv2 (found
11 | * in the COPYING file in the root directory of this source tree).
12 | * You may select, at your option, one of the above-listed licenses.
13 | ****************************************************************** */
14 |
15 |
16 | /*
17 | * The purpose of this header is to enable debug functions.
18 | * They regroup assert(), DEBUGLOG() and RAWLOG() for run-time,
19 | * and DEBUG_STATIC_ASSERT() for compile-time.
20 | *
21 | * By default, DEBUGLEVEL==0, which means run-time debug is disabled.
22 | *
23 | * Level 1 enables assert() only.
24 | * Starting level 2, traces can be generated and pushed to stderr.
25 | * The higher the level, the more verbose the traces.
26 | *
27 | * It's possible to dynamically adjust level using variable g_debug_level,
28 | * which is only declared if DEBUGLEVEL>=2,
29 | * and is a global variable, not multi-thread protected (use with care)
30 | */
31 |
32 | #ifndef DEBUG_H_12987983217
33 | #define DEBUG_H_12987983217
34 |
35 | #if defined (__cplusplus)
36 | extern "C" {
37 | #endif
38 |
39 |
40 | /* static assert is triggered at compile time, leaving no runtime artefact.
41 | * static assert only works with compile-time constants.
42 | * Also, this variant can only be used inside a function. */
43 | #define DEBUG_STATIC_ASSERT(c) (void)sizeof(char[(c) ? 1 : -1])
44 |
45 |
46 | /* DEBUGLEVEL is expected to be defined externally,
47 | * typically through compiler command line.
48 | * Value must be a number. */
49 | #ifndef DEBUGLEVEL
50 | # define DEBUGLEVEL 0
51 | #endif
52 |
53 |
54 | /* recommended values for DEBUGLEVEL :
55 | * 0 : release mode, no debug, all run-time checks disabled
56 | * 1 : enables assert() only, no display
57 | * 2 : reserved, for currently active debug path
58 | * 3 : events once per object lifetime (CCtx, CDict, etc.)
59 | * 4 : events once per frame
60 | * 5 : events once per block
61 | * 6 : events once per sequence (verbose)
62 | * 7+: events at every position (*very* verbose)
63 | *
64 | * It's generally inconvenient to output traces > 5.
65 | * In which case, it's possible to selectively trigger high verbosity levels
66 | * by modifying g_debug_level.
67 | */
68 |
69 | #if (DEBUGLEVEL>=1)
70 | # define ZSTD_DEPS_NEED_ASSERT
71 | # include "zstd_deps.h"
72 | #else
73 | # ifndef assert /* assert may be already defined, due to prior #include */
74 | # define assert(condition) ((void)0) /* disable assert (default) */
75 | # endif
76 | #endif
77 |
78 | #if (DEBUGLEVEL>=2)
79 | # define ZSTD_DEPS_NEED_IO
80 | # include "zstd_deps.h"
81 | extern int g_debuglevel; /* the variable is only declared,
82 | it actually lives in debug.c,
83 | and is shared by the whole process.
84 | It's not thread-safe.
85 | It's useful when enabling very verbose levels
86 | on selective conditions (such as position in src) */
87 |
88 | # define RAWLOG(l, ...) { \
89 | if (l<=g_debuglevel) { \
90 | ZSTD_DEBUG_PRINT(__VA_ARGS__); \
91 | } }
92 | # define DEBUGLOG(l, ...) { \
93 | if (l<=g_debuglevel) { \
94 | ZSTD_DEBUG_PRINT(__FILE__ ": " __VA_ARGS__); \
95 | ZSTD_DEBUG_PRINT(" \n"); \
96 | } }
97 | #else
98 | # define RAWLOG(l, ...) {} /* disabled */
99 | # define DEBUGLOG(l, ...) {} /* disabled */
100 | #endif
101 |
102 |
103 | #if defined (__cplusplus)
104 | }
105 | #endif
106 |
107 | #endif /* DEBUG_H_12987983217 */
108 |
--------------------------------------------------------------------------------
/Extra/zstd/common/error_private.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) Yann Collet, Facebook, Inc.
3 | * All rights reserved.
4 | *
5 | * This source code is licensed under both the BSD-style license (found in the
6 | * LICENSE file in the root directory of this source tree) and the GPLv2 (found
7 | * in the COPYING file in the root directory of this source tree).
8 | * You may select, at your option, one of the above-listed licenses.
9 | */
10 |
11 | /* The purpose of this file is to have a single list of error strings embedded in binary */
12 |
13 | #include "error_private.h"
14 |
15 | const char* ERR_getErrorString(ERR_enum code)
16 | {
17 | #ifdef ZSTD_STRIP_ERROR_STRINGS
18 | (void)code;
19 | return "Error strings stripped";
20 | #else
21 | static const char* const notErrorCode = "Unspecified error code";
22 | switch( code )
23 | {
24 | case PREFIX(no_error): return "No error detected";
25 | case PREFIX(GENERIC): return "Error (generic)";
26 | case PREFIX(prefix_unknown): return "Unknown frame descriptor";
27 | case PREFIX(version_unsupported): return "Version not supported";
28 | case PREFIX(frameParameter_unsupported): return "Unsupported frame parameter";
29 | case PREFIX(frameParameter_windowTooLarge): return "Frame requires too much memory for decoding";
30 | case PREFIX(corruption_detected): return "Corrupted block detected";
31 | case PREFIX(checksum_wrong): return "Restored data doesn't match checksum";
32 | case PREFIX(parameter_unsupported): return "Unsupported parameter";
33 | case PREFIX(parameter_outOfBound): return "Parameter is out of bound";
34 | case PREFIX(init_missing): return "Context should be init first";
35 | case PREFIX(memory_allocation): return "Allocation error : not enough memory";
36 | case PREFIX(workSpace_tooSmall): return "workSpace buffer is not large enough";
37 | case PREFIX(stage_wrong): return "Operation not authorized at current processing stage";
38 | case PREFIX(tableLog_tooLarge): return "tableLog requires too much memory : unsupported";
39 | case PREFIX(maxSymbolValue_tooLarge): return "Unsupported max Symbol Value : too large";
40 | case PREFIX(maxSymbolValue_tooSmall): return "Specified maxSymbolValue is too small";
41 | case PREFIX(dictionary_corrupted): return "Dictionary is corrupted";
42 | case PREFIX(dictionary_wrong): return "Dictionary mismatch";
43 | case PREFIX(dictionaryCreation_failed): return "Cannot create Dictionary from provided samples";
44 | case PREFIX(dstSize_tooSmall): return "Destination buffer is too small";
45 | case PREFIX(srcSize_wrong): return "Src size is incorrect";
46 | case PREFIX(dstBuffer_null): return "Operation on NULL destination buffer";
47 | /* following error codes are not stable and may be removed or changed in a future version */
48 | case PREFIX(frameIndex_tooLarge): return "Frame index is too large";
49 | case PREFIX(seekableIO): return "An I/O error occurred when reading/seeking";
50 | case PREFIX(dstBuffer_wrong): return "Destination buffer is wrong";
51 | case PREFIX(srcBuffer_wrong): return "Source buffer is wrong";
52 | case PREFIX(maxCode):
53 | default: return notErrorCode;
54 | }
55 | #endif
56 | }
57 |
--------------------------------------------------------------------------------
/Extra/zstd/common/error_private.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) Yann Collet, Facebook, Inc.
3 | * All rights reserved.
4 | *
5 | * This source code is licensed under both the BSD-style license (found in the
6 | * LICENSE file in the root directory of this source tree) and the GPLv2 (found
7 | * in the COPYING file in the root directory of this source tree).
8 | * You may select, at your option, one of the above-listed licenses.
9 | */
10 |
11 | /* Note : this module is expected to remain private, do not expose it */
12 |
13 | #ifndef ERROR_H_MODULE
14 | #define ERROR_H_MODULE
15 |
16 | #if defined (__cplusplus)
17 | extern "C" {
18 | #endif
19 |
20 |
21 | /* ****************************************
22 | * Dependencies
23 | ******************************************/
24 | #include "../zstd_errors.h" /* enum list */
25 | #include "zstd_deps.h" /* size_t */
26 |
27 |
28 | /* ****************************************
29 | * Compiler-specific
30 | ******************************************/
31 | #if defined(__GNUC__)
32 | # define ERR_STATIC static __attribute__((unused))
33 | #elif defined (__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */)
34 | # define ERR_STATIC static inline
35 | #elif defined(_MSC_VER)
36 | # define ERR_STATIC static __inline
37 | #else
38 | # define ERR_STATIC static /* this version may generate warnings for unused static functions; disable the relevant warning */
39 | #endif
40 |
41 |
42 | /*-****************************************
43 | * Customization (error_public.h)
44 | ******************************************/
45 | typedef ZSTD_ErrorCode ERR_enum;
46 | #define PREFIX(name) ZSTD_error_##name
47 |
48 |
49 | /*-****************************************
50 | * Error codes handling
51 | ******************************************/
52 | #undef ERROR /* already defined on Visual Studio */
53 | #define ERROR(name) ZSTD_ERROR(name)
54 | #define ZSTD_ERROR(name) ((size_t)-PREFIX(name))
55 |
56 | ERR_STATIC unsigned ERR_isError(size_t code) { return (code > ERROR(maxCode)); }
57 |
58 | ERR_STATIC ERR_enum ERR_getErrorCode(size_t code) { if (!ERR_isError(code)) return (ERR_enum)0; return (ERR_enum) (0-code); }
59 |
60 | /* check and forward error code */
61 | #define CHECK_V_F(e, f) size_t const e = f; if (ERR_isError(e)) return e
62 | #define CHECK_F(f) { CHECK_V_F(_var_err__, f); }
63 |
64 |
65 | /*-****************************************
66 | * Error Strings
67 | ******************************************/
68 |
69 | const char* ERR_getErrorString(ERR_enum code); /* error_private.c */
70 |
71 | ERR_STATIC const char* ERR_getErrorName(size_t code)
72 | {
73 | return ERR_getErrorString(ERR_getErrorCode(code));
74 | }
75 |
76 | #if defined (__cplusplus)
77 | }
78 | #endif
79 |
80 | #endif /* ERROR_H_MODULE */
81 |
--------------------------------------------------------------------------------
/Extra/zstd/common/pool.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) Yann Collet, Facebook, Inc.
3 | * All rights reserved.
4 | *
5 | * This source code is licensed under both the BSD-style license (found in the
6 | * LICENSE file in the root directory of this source tree) and the GPLv2 (found
7 | * in the COPYING file in the root directory of this source tree).
8 | * You may select, at your option, one of the above-listed licenses.
9 | */
10 |
11 | #ifndef POOL_H
12 | #define POOL_H
13 |
14 | #if defined (__cplusplus)
15 | extern "C" {
16 | #endif
17 |
18 |
19 | #include "zstd_deps.h"
20 | #define ZSTD_STATIC_LINKING_ONLY /* ZSTD_customMem */
21 | #include "../zstd.h"
22 |
23 | typedef struct POOL_ctx_s POOL_ctx;
24 |
25 | /*! POOL_create() :
26 | * Create a thread pool with at most `numThreads` threads.
27 | * `numThreads` must be at least 1.
28 | * The maximum number of queued jobs before blocking is `queueSize`.
29 | * @return : POOL_ctx pointer on success, else NULL.
30 | */
31 | POOL_ctx* POOL_create(size_t numThreads, size_t queueSize);
32 |
33 | POOL_ctx* POOL_create_advanced(size_t numThreads, size_t queueSize,
34 | ZSTD_customMem customMem);
35 |
36 | /*! POOL_free() :
37 | * Free a thread pool returned by POOL_create().
38 | */
39 | void POOL_free(POOL_ctx* ctx);
40 |
41 | /*! POOL_resize() :
42 | * Expands or shrinks pool's number of threads.
43 | * This is more efficient than releasing + creating a new context,
44 | * since it tries to preserve and re-use existing threads.
45 | * `numThreads` must be at least 1.
46 | * @return : 0 when resize was successful,
47 | * !0 (typically 1) if there is an error.
48 | * note : only numThreads can be resized, queueSize remains unchanged.
49 | */
50 | int POOL_resize(POOL_ctx* ctx, size_t numThreads);
51 |
52 | /*! POOL_sizeof() :
53 | * @return threadpool memory usage
54 | * note : compatible with NULL (returns 0 in this case)
55 | */
56 | size_t POOL_sizeof(POOL_ctx* ctx);
57 |
58 | /*! POOL_function :
59 | * The function type that can be added to a thread pool.
60 | */
61 | typedef void (*POOL_function)(void*);
62 |
63 | /*! POOL_add() :
64 | * Add the job `function(opaque)` to the thread pool. `ctx` must be valid.
65 | * Possibly blocks until there is room in the queue.
66 | * Note : The function may be executed asynchronously,
67 | * therefore, `opaque` must live until function has been completed.
68 | */
69 | void POOL_add(POOL_ctx* ctx, POOL_function function, void* opaque);
70 |
71 |
72 | /*! POOL_tryAdd() :
73 | * Add the job `function(opaque)` to thread pool _if_ a worker is available.
74 | * Returns immediately even if not (does not block).
75 | * @return : 1 if successful, 0 if not.
76 | */
77 | int POOL_tryAdd(POOL_ctx* ctx, POOL_function function, void* opaque);
78 |
79 |
80 | #if defined (__cplusplus)
81 | }
82 | #endif
83 |
84 | #endif
85 |
--------------------------------------------------------------------------------
/Extra/zstd/common/threading.c:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2016 Tino Reichardt
3 | * All rights reserved.
4 | *
5 | * You can contact the author at:
6 | * - zstdmt source repository: https://github.com/mcmilk/zstdmt
7 | *
8 | * This source code is licensed under both the BSD-style license (found in the
9 | * LICENSE file in the root directory of this source tree) and the GPLv2 (found
10 | * in the COPYING file in the root directory of this source tree).
11 | * You may select, at your option, one of the above-listed licenses.
12 | */
13 |
14 | /**
15 | * This file will hold wrapper for systems, which do not support pthreads
16 | */
17 |
18 | #include "threading.h"
19 |
20 | /* create fake symbol to avoid empty translation unit warning */
21 | int g_ZSTD_threading_useless_symbol;
22 |
23 | #if defined(ZSTD_MULTITHREAD) && defined(_WIN32)
24 |
25 | /**
26 | * Windows minimalist Pthread Wrapper, based on :
27 | * http://www.cse.wustl.edu/~schmidt/win32-cv-1.html
28 | */
29 |
30 |
31 | /* === Dependencies === */
32 | #include
33 | #include
34 |
35 |
36 | /* === Implementation === */
37 |
38 | static unsigned __stdcall worker(void *arg)
39 | {
40 | ZSTD_pthread_t* const thread = (ZSTD_pthread_t*) arg;
41 | thread->arg = thread->start_routine(thread->arg);
42 | return 0;
43 | }
44 |
45 | int ZSTD_pthread_create(ZSTD_pthread_t* thread, const void* unused,
46 | void* (*start_routine) (void*), void* arg)
47 | {
48 | (void)unused;
49 | thread->arg = arg;
50 | thread->start_routine = start_routine;
51 | thread->handle = (HANDLE) _beginthreadex(NULL, 0, worker, thread, 0, NULL);
52 |
53 | if (!thread->handle)
54 | return errno;
55 | else
56 | return 0;
57 | }
58 |
59 | int ZSTD_pthread_join(ZSTD_pthread_t thread, void **value_ptr)
60 | {
61 | DWORD result;
62 |
63 | if (!thread.handle) return 0;
64 |
65 | result = WaitForSingleObject(thread.handle, INFINITE);
66 | switch (result) {
67 | case WAIT_OBJECT_0:
68 | if (value_ptr) *value_ptr = thread.arg;
69 | return 0;
70 | case WAIT_ABANDONED:
71 | return EINVAL;
72 | default:
73 | return GetLastError();
74 | }
75 | }
76 |
77 | #endif /* ZSTD_MULTITHREAD */
78 |
79 | #if defined(ZSTD_MULTITHREAD) && DEBUGLEVEL >= 1 && !defined(_WIN32)
80 |
81 | #define ZSTD_DEPS_NEED_MALLOC
82 | #include "zstd_deps.h"
83 |
84 | int ZSTD_pthread_mutex_init(ZSTD_pthread_mutex_t* mutex, pthread_mutexattr_t const* attr)
85 | {
86 | *mutex = (pthread_mutex_t*)ZSTD_malloc(sizeof(pthread_mutex_t));
87 | if (!*mutex)
88 | return 1;
89 | return pthread_mutex_init(*mutex, attr);
90 | }
91 |
92 | int ZSTD_pthread_mutex_destroy(ZSTD_pthread_mutex_t* mutex)
93 | {
94 | if (!*mutex)
95 | return 0;
96 | {
97 | int const ret = pthread_mutex_destroy(*mutex);
98 | ZSTD_free(*mutex);
99 | return ret;
100 | }
101 | }
102 |
103 | int ZSTD_pthread_cond_init(ZSTD_pthread_cond_t* cond, pthread_condattr_t const* attr)
104 | {
105 | *cond = (pthread_cond_t*)ZSTD_malloc(sizeof(pthread_cond_t));
106 | if (!*cond)
107 | return 1;
108 | return pthread_cond_init(*cond, attr);
109 | }
110 |
111 | int ZSTD_pthread_cond_destroy(ZSTD_pthread_cond_t* cond)
112 | {
113 | if (!*cond)
114 | return 0;
115 | {
116 | int const ret = pthread_cond_destroy(*cond);
117 | ZSTD_free(*cond);
118 | return ret;
119 | }
120 | }
121 |
122 | #endif
123 |
--------------------------------------------------------------------------------
/Extra/zstd/common/zstd_common.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) Yann Collet, Facebook, Inc.
3 | * All rights reserved.
4 | *
5 | * This source code is licensed under both the BSD-style license (found in the
6 | * LICENSE file in the root directory of this source tree) and the GPLv2 (found
7 | * in the COPYING file in the root directory of this source tree).
8 | * You may select, at your option, one of the above-listed licenses.
9 | */
10 |
11 |
12 |
13 | /*-*************************************
14 | * Dependencies
15 | ***************************************/
16 | #define ZSTD_DEPS_NEED_MALLOC
17 | #include "zstd_deps.h" /* ZSTD_malloc, ZSTD_calloc, ZSTD_free, ZSTD_memset */
18 | #include "error_private.h"
19 | #include "zstd_internal.h"
20 |
21 |
22 | /*-****************************************
23 | * Version
24 | ******************************************/
25 | unsigned ZSTD_versionNumber(void) { return ZSTD_VERSION_NUMBER; }
26 |
27 | const char* ZSTD_versionString(void) { return ZSTD_VERSION_STRING; }
28 |
29 |
30 | /*-****************************************
31 | * ZSTD Error Management
32 | ******************************************/
33 | #undef ZSTD_isError /* defined within zstd_internal.h */
34 | /*! ZSTD_isError() :
35 | * tells if a return value is an error code
36 | * symbol is required for external callers */
37 | unsigned ZSTD_isError(size_t code) { return ERR_isError(code); }
38 |
39 | /*! ZSTD_getErrorName() :
40 | * provides error code string from function result (useful for debugging) */
41 | const char* ZSTD_getErrorName(size_t code) { return ERR_getErrorName(code); }
42 |
43 | /*! ZSTD_getError() :
44 | * convert a `size_t` function result into a proper ZSTD_errorCode enum */
45 | ZSTD_ErrorCode ZSTD_getErrorCode(size_t code) { return ERR_getErrorCode(code); }
46 |
47 | /*! ZSTD_getErrorString() :
48 | * provides error code string from enum */
49 | const char* ZSTD_getErrorString(ZSTD_ErrorCode code) { return ERR_getErrorString(code); }
50 |
51 |
52 |
53 | /*=**************************************************************
54 | * Custom allocator
55 | ****************************************************************/
56 | void* ZSTD_customMalloc(size_t size, ZSTD_customMem customMem)
57 | {
58 | if (customMem.customAlloc)
59 | return customMem.customAlloc(customMem.opaque, size);
60 | return ZSTD_malloc(size);
61 | }
62 |
63 | void* ZSTD_customCalloc(size_t size, ZSTD_customMem customMem)
64 | {
65 | if (customMem.customAlloc) {
66 | /* calloc implemented as malloc+memset;
67 | * not as efficient as calloc, but next best guess for custom malloc */
68 | void* const ptr = customMem.customAlloc(customMem.opaque, size);
69 | ZSTD_memset(ptr, 0, size);
70 | return ptr;
71 | }
72 | return ZSTD_calloc(1, size);
73 | }
74 |
75 | void ZSTD_customFree(void* ptr, ZSTD_customMem customMem)
76 | {
77 | if (ptr!=NULL) {
78 | if (customMem.customFree)
79 | customMem.customFree(customMem.opaque, ptr);
80 | else
81 | ZSTD_free(ptr);
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/Extra/zstd/common/zstd_deps.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) Facebook, Inc.
3 | * All rights reserved.
4 | *
5 | * This source code is licensed under both the BSD-style license (found in the
6 | * LICENSE file in the root directory of this source tree) and the GPLv2 (found
7 | * in the COPYING file in the root directory of this source tree).
8 | * You may select, at your option, one of the above-listed licenses.
9 | */
10 |
11 | /* This file provides common libc dependencies that zstd requires.
12 | * The purpose is to allow replacing this file with a custom implementation
13 | * to compile zstd without libc support.
14 | */
15 |
16 | /* Need:
17 | * NULL
18 | * INT_MAX
19 | * UINT_MAX
20 | * ZSTD_memcpy()
21 | * ZSTD_memset()
22 | * ZSTD_memmove()
23 | */
24 | #ifndef ZSTD_DEPS_COMMON
25 | #define ZSTD_DEPS_COMMON
26 |
27 | #include
28 | #include
29 | #include
30 |
31 | #if defined(__GNUC__) && __GNUC__ >= 4
32 | # define ZSTD_memcpy(d,s,l) __builtin_memcpy((d),(s),(l))
33 | # define ZSTD_memmove(d,s,l) __builtin_memmove((d),(s),(l))
34 | # define ZSTD_memset(p,v,l) __builtin_memset((p),(v),(l))
35 | #else
36 | # define ZSTD_memcpy(d,s,l) memcpy((d),(s),(l))
37 | # define ZSTD_memmove(d,s,l) memmove((d),(s),(l))
38 | # define ZSTD_memset(p,v,l) memset((p),(v),(l))
39 | #endif
40 |
41 | #endif /* ZSTD_DEPS_COMMON */
42 |
43 | /* Need:
44 | * ZSTD_malloc()
45 | * ZSTD_free()
46 | * ZSTD_calloc()
47 | */
48 | #ifdef ZSTD_DEPS_NEED_MALLOC
49 | #ifndef ZSTD_DEPS_MALLOC
50 | #define ZSTD_DEPS_MALLOC
51 |
52 | #include
53 |
54 | #define ZSTD_malloc(s) malloc(s)
55 | #define ZSTD_calloc(n,s) calloc((n), (s))
56 | #define ZSTD_free(p) free((p))
57 |
58 | #endif /* ZSTD_DEPS_MALLOC */
59 | #endif /* ZSTD_DEPS_NEED_MALLOC */
60 |
61 | /*
62 | * Provides 64-bit math support.
63 | * Need:
64 | * U64 ZSTD_div64(U64 dividend, U32 divisor)
65 | */
66 | #ifdef ZSTD_DEPS_NEED_MATH64
67 | #ifndef ZSTD_DEPS_MATH64
68 | #define ZSTD_DEPS_MATH64
69 |
70 | #define ZSTD_div64(dividend, divisor) ((dividend) / (divisor))
71 |
72 | #endif /* ZSTD_DEPS_MATH64 */
73 | #endif /* ZSTD_DEPS_NEED_MATH64 */
74 |
75 | /* Need:
76 | * assert()
77 | */
78 | #ifdef ZSTD_DEPS_NEED_ASSERT
79 | #ifndef ZSTD_DEPS_ASSERT
80 | #define ZSTD_DEPS_ASSERT
81 |
82 | #include
83 |
84 | #endif /* ZSTD_DEPS_ASSERT */
85 | #endif /* ZSTD_DEPS_NEED_ASSERT */
86 |
87 | /* Need:
88 | * ZSTD_DEBUG_PRINT()
89 | */
90 | #ifdef ZSTD_DEPS_NEED_IO
91 | #ifndef ZSTD_DEPS_IO
92 | #define ZSTD_DEPS_IO
93 |
94 | #include
95 | #define ZSTD_DEBUG_PRINT(...) fprintf(stderr, __VA_ARGS__)
96 |
97 | #endif /* ZSTD_DEPS_IO */
98 | #endif /* ZSTD_DEPS_NEED_IO */
99 |
100 | /* Only requested when is known to be present.
101 | * Need:
102 | * intptr_t
103 | */
104 | #ifdef ZSTD_DEPS_NEED_STDINT
105 | #ifndef ZSTD_DEPS_STDINT
106 | #define ZSTD_DEPS_STDINT
107 |
108 | #include
109 |
110 | #endif /* ZSTD_DEPS_STDINT */
111 | #endif /* ZSTD_DEPS_NEED_STDINT */
112 |
--------------------------------------------------------------------------------
/Extra/zstd/compress/hist.h:
--------------------------------------------------------------------------------
1 | /* ******************************************************************
2 | * hist : Histogram functions
3 | * part of Finite State Entropy project
4 | * Copyright (c) Yann Collet, Facebook, Inc.
5 | *
6 | * You can contact the author at :
7 | * - FSE source repository : https://github.com/Cyan4973/FiniteStateEntropy
8 | * - Public forum : https://groups.google.com/forum/#!forum/lz4c
9 | *
10 | * This source code is licensed under both the BSD-style license (found in the
11 | * LICENSE file in the root directory of this source tree) and the GPLv2 (found
12 | * in the COPYING file in the root directory of this source tree).
13 | * You may select, at your option, one of the above-listed licenses.
14 | ****************************************************************** */
15 |
16 | /* --- dependencies --- */
17 | #include "../common/zstd_deps.h" /* size_t */
18 |
19 |
20 | /* --- simple histogram functions --- */
21 |
22 | /*! HIST_count():
23 | * Provides the precise count of each byte within a table 'count'.
24 | * 'count' is a table of unsigned int, of minimum size (*maxSymbolValuePtr+1).
25 | * Updates *maxSymbolValuePtr with actual largest symbol value detected.
26 | * @return : count of the most frequent symbol (which isn't identified).
27 | * or an error code, which can be tested using HIST_isError().
28 | * note : if return == srcSize, there is only one symbol.
29 | */
30 | size_t HIST_count(unsigned* count, unsigned* maxSymbolValuePtr,
31 | const void* src, size_t srcSize);
32 |
33 | unsigned HIST_isError(size_t code); /**< tells if a return value is an error code */
34 |
35 |
36 | /* --- advanced histogram functions --- */
37 |
38 | #define HIST_WKSP_SIZE_U32 1024
39 | #define HIST_WKSP_SIZE (HIST_WKSP_SIZE_U32 * sizeof(unsigned))
40 | /** HIST_count_wksp() :
41 | * Same as HIST_count(), but using an externally provided scratch buffer.
42 | * Benefit is this function will use very little stack space.
43 | * `workSpace` is a writable buffer which must be 4-bytes aligned,
44 | * `workSpaceSize` must be >= HIST_WKSP_SIZE
45 | */
46 | size_t HIST_count_wksp(unsigned* count, unsigned* maxSymbolValuePtr,
47 | const void* src, size_t srcSize,
48 | void* workSpace, size_t workSpaceSize);
49 |
50 | /** HIST_countFast() :
51 | * same as HIST_count(), but blindly trusts that all byte values within src are <= *maxSymbolValuePtr.
52 | * This function is unsafe, and will segfault if any value within `src` is `> *maxSymbolValuePtr`
53 | */
54 | size_t HIST_countFast(unsigned* count, unsigned* maxSymbolValuePtr,
55 | const void* src, size_t srcSize);
56 |
57 | /** HIST_countFast_wksp() :
58 | * Same as HIST_countFast(), but using an externally provided scratch buffer.
59 | * `workSpace` is a writable buffer which must be 4-bytes aligned,
60 | * `workSpaceSize` must be >= HIST_WKSP_SIZE
61 | */
62 | size_t HIST_countFast_wksp(unsigned* count, unsigned* maxSymbolValuePtr,
63 | const void* src, size_t srcSize,
64 | void* workSpace, size_t workSpaceSize);
65 |
66 | /*! HIST_count_simple() :
67 | * Same as HIST_countFast(), this function is unsafe,
68 | * and will segfault if any value within `src` is `> *maxSymbolValuePtr`.
69 | * It is also a bit slower for large inputs.
70 | * However, it does not need any additional memory (not even on stack).
71 | * @return : count of the most frequent symbol.
72 | * Note this function doesn't produce any error (i.e. it must succeed).
73 | */
74 | unsigned HIST_count_simple(unsigned* count, unsigned* maxSymbolValuePtr,
75 | const void* src, size_t srcSize);
76 |
--------------------------------------------------------------------------------
/Extra/zstd/compress/zstd_compress_literals.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) Yann Collet, Facebook, Inc.
3 | * All rights reserved.
4 | *
5 | * This source code is licensed under both the BSD-style license (found in the
6 | * LICENSE file in the root directory of this source tree) and the GPLv2 (found
7 | * in the COPYING file in the root directory of this source tree).
8 | * You may select, at your option, one of the above-listed licenses.
9 | */
10 |
11 | #ifndef ZSTD_COMPRESS_LITERALS_H
12 | #define ZSTD_COMPRESS_LITERALS_H
13 |
14 | #include "zstd_compress_internal.h" /* ZSTD_hufCTables_t, ZSTD_minGain() */
15 |
16 |
17 | size_t ZSTD_noCompressLiterals (void* dst, size_t dstCapacity, const void* src, size_t srcSize);
18 |
19 | size_t ZSTD_compressRleLiteralsBlock (void* dst, size_t dstCapacity, const void* src, size_t srcSize);
20 |
21 | size_t ZSTD_compressLiterals (ZSTD_hufCTables_t const* prevHuf,
22 | ZSTD_hufCTables_t* nextHuf,
23 | ZSTD_strategy strategy, int disableLiteralCompression,
24 | void* dst, size_t dstCapacity,
25 | const void* src, size_t srcSize,
26 | void* entropyWorkspace, size_t entropyWorkspaceSize,
27 | const int bmi2);
28 |
29 | #endif /* ZSTD_COMPRESS_LITERALS_H */
30 |
--------------------------------------------------------------------------------
/Extra/zstd/compress/zstd_compress_sequences.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) Yann Collet, Facebook, Inc.
3 | * All rights reserved.
4 | *
5 | * This source code is licensed under both the BSD-style license (found in the
6 | * LICENSE file in the root directory of this source tree) and the GPLv2 (found
7 | * in the COPYING file in the root directory of this source tree).
8 | * You may select, at your option, one of the above-listed licenses.
9 | */
10 |
11 | #ifndef ZSTD_COMPRESS_SEQUENCES_H
12 | #define ZSTD_COMPRESS_SEQUENCES_H
13 |
14 | #include "../common/fse.h" /* FSE_repeat, FSE_CTable */
15 | #include "../common/zstd_internal.h" /* symbolEncodingType_e, ZSTD_strategy */
16 |
17 | typedef enum {
18 | ZSTD_defaultDisallowed = 0,
19 | ZSTD_defaultAllowed = 1
20 | } ZSTD_defaultPolicy_e;
21 |
22 | symbolEncodingType_e
23 | ZSTD_selectEncodingType(
24 | FSE_repeat* repeatMode, unsigned const* count, unsigned const max,
25 | size_t const mostFrequent, size_t nbSeq, unsigned const FSELog,
26 | FSE_CTable const* prevCTable,
27 | short const* defaultNorm, U32 defaultNormLog,
28 | ZSTD_defaultPolicy_e const isDefaultAllowed,
29 | ZSTD_strategy const strategy);
30 |
31 | size_t
32 | ZSTD_buildCTable(void* dst, size_t dstCapacity,
33 | FSE_CTable* nextCTable, U32 FSELog, symbolEncodingType_e type,
34 | unsigned* count, U32 max,
35 | const BYTE* codeTable, size_t nbSeq,
36 | const S16* defaultNorm, U32 defaultNormLog, U32 defaultMax,
37 | const FSE_CTable* prevCTable, size_t prevCTableSize,
38 | void* entropyWorkspace, size_t entropyWorkspaceSize);
39 |
40 | size_t ZSTD_encodeSequences(
41 | void* dst, size_t dstCapacity,
42 | FSE_CTable const* CTable_MatchLength, BYTE const* mlCodeTable,
43 | FSE_CTable const* CTable_OffsetBits, BYTE const* ofCodeTable,
44 | FSE_CTable const* CTable_LitLength, BYTE const* llCodeTable,
45 | seqDef const* sequences, size_t nbSeq, int longOffsets, int bmi2);
46 |
47 | size_t ZSTD_fseBitCost(
48 | FSE_CTable const* ctable,
49 | unsigned const* count,
50 | unsigned const max);
51 |
52 | size_t ZSTD_crossEntropyCost(short const* norm, unsigned accuracyLog,
53 | unsigned const* count, unsigned const max);
54 | #endif /* ZSTD_COMPRESS_SEQUENCES_H */
55 |
--------------------------------------------------------------------------------
/Extra/zstd/compress/zstd_compress_superblock.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) Yann Collet, Facebook, Inc.
3 | * All rights reserved.
4 | *
5 | * This source code is licensed under both the BSD-style license (found in the
6 | * LICENSE file in the root directory of this source tree) and the GPLv2 (found
7 | * in the COPYING file in the root directory of this source tree).
8 | * You may select, at your option, one of the above-listed licenses.
9 | */
10 |
11 | #ifndef ZSTD_COMPRESS_ADVANCED_H
12 | #define ZSTD_COMPRESS_ADVANCED_H
13 |
14 | /*-*************************************
15 | * Dependencies
16 | ***************************************/
17 |
18 | #include "../zstd.h" /* ZSTD_CCtx */
19 |
20 | /*-*************************************
21 | * Target Compressed Block Size
22 | ***************************************/
23 |
24 | /* ZSTD_compressSuperBlock() :
25 | * Used to compress a super block when targetCBlockSize is being used.
26 | * The given block will be compressed into multiple sub blocks that are around targetCBlockSize. */
27 | size_t ZSTD_compressSuperBlock(ZSTD_CCtx* zc,
28 | void* dst, size_t dstCapacity,
29 | void const* src, size_t srcSize,
30 | unsigned lastBlock);
31 |
32 | #endif /* ZSTD_COMPRESS_ADVANCED_H */
33 |
--------------------------------------------------------------------------------
/Extra/zstd/compress/zstd_double_fast.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) Yann Collet, Facebook, Inc.
3 | * All rights reserved.
4 | *
5 | * This source code is licensed under both the BSD-style license (found in the
6 | * LICENSE file in the root directory of this source tree) and the GPLv2 (found
7 | * in the COPYING file in the root directory of this source tree).
8 | * You may select, at your option, one of the above-listed licenses.
9 | */
10 |
11 | #ifndef ZSTD_DOUBLE_FAST_H
12 | #define ZSTD_DOUBLE_FAST_H
13 |
14 | #if defined (__cplusplus)
15 | extern "C" {
16 | #endif
17 |
18 | #include "../common/mem.h" /* U32 */
19 | #include "zstd_compress_internal.h" /* ZSTD_CCtx, size_t */
20 |
21 | void ZSTD_fillDoubleHashTable(ZSTD_matchState_t* ms,
22 | void const* end, ZSTD_dictTableLoadMethod_e dtlm);
23 | size_t ZSTD_compressBlock_doubleFast(
24 | ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
25 | void const* src, size_t srcSize);
26 | size_t ZSTD_compressBlock_doubleFast_dictMatchState(
27 | ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
28 | void const* src, size_t srcSize);
29 | size_t ZSTD_compressBlock_doubleFast_extDict(
30 | ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
31 | void const* src, size_t srcSize);
32 |
33 |
34 | #if defined (__cplusplus)
35 | }
36 | #endif
37 |
38 | #endif /* ZSTD_DOUBLE_FAST_H */
39 |
--------------------------------------------------------------------------------
/Extra/zstd/compress/zstd_fast.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) Yann Collet, Facebook, Inc.
3 | * All rights reserved.
4 | *
5 | * This source code is licensed under both the BSD-style license (found in the
6 | * LICENSE file in the root directory of this source tree) and the GPLv2 (found
7 | * in the COPYING file in the root directory of this source tree).
8 | * You may select, at your option, one of the above-listed licenses.
9 | */
10 |
11 | #ifndef ZSTD_FAST_H
12 | #define ZSTD_FAST_H
13 |
14 | #if defined (__cplusplus)
15 | extern "C" {
16 | #endif
17 |
18 | #include "../common/mem.h" /* U32 */
19 | #include "zstd_compress_internal.h"
20 |
21 | void ZSTD_fillHashTable(ZSTD_matchState_t* ms,
22 | void const* end, ZSTD_dictTableLoadMethod_e dtlm);
23 | size_t ZSTD_compressBlock_fast(
24 | ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
25 | void const* src, size_t srcSize);
26 | size_t ZSTD_compressBlock_fast_dictMatchState(
27 | ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
28 | void const* src, size_t srcSize);
29 | size_t ZSTD_compressBlock_fast_extDict(
30 | ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
31 | void const* src, size_t srcSize);
32 |
33 | #if defined (__cplusplus)
34 | }
35 | #endif
36 |
37 | #endif /* ZSTD_FAST_H */
38 |
--------------------------------------------------------------------------------
/Extra/zstd/compress/zstd_opt.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) Yann Collet, Facebook, Inc.
3 | * All rights reserved.
4 | *
5 | * This source code is licensed under both the BSD-style license (found in the
6 | * LICENSE file in the root directory of this source tree) and the GPLv2 (found
7 | * in the COPYING file in the root directory of this source tree).
8 | * You may select, at your option, one of the above-listed licenses.
9 | */
10 |
11 | #ifndef ZSTD_OPT_H
12 | #define ZSTD_OPT_H
13 |
14 | #if defined (__cplusplus)
15 | extern "C" {
16 | #endif
17 |
18 | #include "zstd_compress_internal.h"
19 |
20 | /* used in ZSTD_loadDictionaryContent() */
21 | void ZSTD_updateTree(ZSTD_matchState_t* ms, const BYTE* ip, const BYTE* iend);
22 |
23 | size_t ZSTD_compressBlock_btopt(
24 | ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
25 | void const* src, size_t srcSize);
26 | size_t ZSTD_compressBlock_btultra(
27 | ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
28 | void const* src, size_t srcSize);
29 | size_t ZSTD_compressBlock_btultra2(
30 | ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
31 | void const* src, size_t srcSize);
32 |
33 |
34 | size_t ZSTD_compressBlock_btopt_dictMatchState(
35 | ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
36 | void const* src, size_t srcSize);
37 | size_t ZSTD_compressBlock_btultra_dictMatchState(
38 | ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
39 | void const* src, size_t srcSize);
40 |
41 | size_t ZSTD_compressBlock_btopt_extDict(
42 | ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
43 | void const* src, size_t srcSize);
44 | size_t ZSTD_compressBlock_btultra_extDict(
45 | ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
46 | void const* src, size_t srcSize);
47 |
48 | /* note : no btultra2 variant for extDict nor dictMatchState,
49 | * because btultra2 is not meant to work with dictionaries
50 | * and is only specific for the first block (no prefix) */
51 |
52 | #if defined (__cplusplus)
53 | }
54 | #endif
55 |
56 | #endif /* ZSTD_OPT_H */
57 |
--------------------------------------------------------------------------------
/Extra/zstd/decompress/zstd_ddict.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) Yann Collet, Facebook, Inc.
3 | * All rights reserved.
4 | *
5 | * This source code is licensed under both the BSD-style license (found in the
6 | * LICENSE file in the root directory of this source tree) and the GPLv2 (found
7 | * in the COPYING file in the root directory of this source tree).
8 | * You may select, at your option, one of the above-listed licenses.
9 | */
10 |
11 |
12 | #ifndef ZSTD_DDICT_H
13 | #define ZSTD_DDICT_H
14 |
15 | /*-*******************************************************
16 | * Dependencies
17 | *********************************************************/
18 | #include "../common/zstd_deps.h" /* size_t */
19 | #include "../zstd.h" /* ZSTD_DDict, and several public functions */
20 |
21 |
22 | /*-*******************************************************
23 | * Interface
24 | *********************************************************/
25 |
26 | /* note: several prototypes are already published in `zstd.h` :
27 | * ZSTD_createDDict()
28 | * ZSTD_createDDict_byReference()
29 | * ZSTD_createDDict_advanced()
30 | * ZSTD_freeDDict()
31 | * ZSTD_initStaticDDict()
32 | * ZSTD_sizeof_DDict()
33 | * ZSTD_estimateDDictSize()
34 | * ZSTD_getDictID_fromDict()
35 | */
36 |
37 | const void* ZSTD_DDict_dictContent(const ZSTD_DDict* ddict);
38 | size_t ZSTD_DDict_dictSize(const ZSTD_DDict* ddict);
39 |
40 | void ZSTD_copyDDictParameters(ZSTD_DCtx* dctx, const ZSTD_DDict* ddict);
41 |
42 |
43 |
44 | #endif /* ZSTD_DDICT_H */
45 |
--------------------------------------------------------------------------------
/Extra/zstd/decompress/zstd_decompress_block.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) Yann Collet, Facebook, Inc.
3 | * All rights reserved.
4 | *
5 | * This source code is licensed under both the BSD-style license (found in the
6 | * LICENSE file in the root directory of this source tree) and the GPLv2 (found
7 | * in the COPYING file in the root directory of this source tree).
8 | * You may select, at your option, one of the above-listed licenses.
9 | */
10 |
11 |
12 | #ifndef ZSTD_DEC_BLOCK_H
13 | #define ZSTD_DEC_BLOCK_H
14 |
15 | /*-*******************************************************
16 | * Dependencies
17 | *********************************************************/
18 | #include "../common/zstd_deps.h" /* size_t */
19 | #include "../zstd.h" /* DCtx, and some public functions */
20 | #include "../common/zstd_internal.h" /* blockProperties_t, and some public functions */
21 | #include "zstd_decompress_internal.h" /* ZSTD_seqSymbol */
22 |
23 |
24 | /* === Prototypes === */
25 |
26 | /* note: prototypes already published within `zstd.h` :
27 | * ZSTD_decompressBlock()
28 | */
29 |
30 | /* note: prototypes already published within `zstd_internal.h` :
31 | * ZSTD_getcBlockSize()
32 | * ZSTD_decodeSeqHeaders()
33 | */
34 |
35 |
36 | /* ZSTD_decompressBlock_internal() :
37 | * decompress block, starting at `src`,
38 | * into destination buffer `dst`.
39 | * @return : decompressed block size,
40 | * or an error code (which can be tested using ZSTD_isError())
41 | */
42 | size_t ZSTD_decompressBlock_internal(ZSTD_DCtx* dctx,
43 | void* dst, size_t dstCapacity,
44 | const void* src, size_t srcSize, const int frame);
45 |
46 | /* ZSTD_buildFSETable() :
47 | * generate FSE decoding table for one symbol (ll, ml or off)
48 | * this function must be called with valid parameters only
49 | * (dt is large enough, normalizedCounter distribution total is a power of 2, max is within range, etc.)
50 | * in which case it cannot fail.
51 | * The workspace must be 4-byte aligned and at least ZSTD_BUILD_FSE_TABLE_WKSP_SIZE bytes, which is
52 | * defined in zstd_decompress_internal.h.
53 | * Internal use only.
54 | */
55 | void ZSTD_buildFSETable(ZSTD_seqSymbol* dt,
56 | const short* normalizedCounter, unsigned maxSymbolValue,
57 | const U32* baseValue, const U32* nbAdditionalBits,
58 | unsigned tableLog, void* wksp, size_t wkspSize,
59 | int bmi2);
60 |
61 |
62 | #endif /* ZSTD_DEC_BLOCK_H */
63 |
--------------------------------------------------------------------------------
/Extra/zstd/dictBuilder/divsufsort.h:
--------------------------------------------------------------------------------
1 | /*
2 | * divsufsort.h for libdivsufsort-lite
3 | * Copyright (c) 2003-2008 Yuta Mori All Rights Reserved.
4 | *
5 | * Permission is hereby granted, free of charge, to any person
6 | * obtaining a copy of this software and associated documentation
7 | * files (the "Software"), to deal in the Software without
8 | * restriction, including without limitation the rights to use,
9 | * copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the
11 | * Software is furnished to do so, subject to the following
12 | * conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be
15 | * included in all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
19 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
21 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24 | * OTHER DEALINGS IN THE SOFTWARE.
25 | */
26 |
27 | #ifndef _DIVSUFSORT_H
28 | #define _DIVSUFSORT_H 1
29 |
30 | #ifdef __cplusplus
31 | extern "C" {
32 | #endif /* __cplusplus */
33 |
34 |
35 | /*- Prototypes -*/
36 |
37 | /**
38 | * Constructs the suffix array of a given string.
39 | * @param T [0..n-1] The input string.
40 | * @param SA [0..n-1] The output array of suffixes.
41 | * @param n The length of the given string.
42 | * @param openMP enables OpenMP optimization.
43 | * @return 0 if no error occurred, -1 or -2 otherwise.
44 | */
45 | int
46 | divsufsort(const unsigned char *T, int *SA, int n, int openMP);
47 |
48 | /**
49 | * Constructs the burrows-wheeler transformed string of a given string.
50 | * @param T [0..n-1] The input string.
51 | * @param U [0..n-1] The output string. (can be T)
52 | * @param A [0..n-1] The temporary array. (can be NULL)
53 | * @param n The length of the given string.
54 | * @param num_indexes The length of secondary indexes array. (can be NULL)
55 | * @param indexes The secondary indexes array. (can be NULL)
56 | * @param openMP enables OpenMP optimization.
57 | * @return The primary index if no error occurred, -1 or -2 otherwise.
58 | */
59 | int
60 | divbwt(const unsigned char *T, unsigned char *U, int *A, int n, unsigned char * num_indexes, int * indexes, int openMP);
61 |
62 |
63 | #ifdef __cplusplus
64 | } /* extern "C" */
65 | #endif /* __cplusplus */
66 |
67 | #endif /* _DIVSUFSORT_H */
68 |
--------------------------------------------------------------------------------
/Extra/zstd/zstd_errors.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) Yann Collet, Facebook, Inc.
3 | * All rights reserved.
4 | *
5 | * This source code is licensed under both the BSD-style license (found in the
6 | * LICENSE file in the root directory of this source tree) and the GPLv2 (found
7 | * in the COPYING file in the root directory of this source tree).
8 | * You may select, at your option, one of the above-listed licenses.
9 | */
10 |
11 | #ifndef ZSTD_ERRORS_H_398273423
12 | #define ZSTD_ERRORS_H_398273423
13 |
14 | #if defined (__cplusplus)
15 | extern "C" {
16 | #endif
17 |
18 | /*===== dependency =====*/
19 | #include /* size_t */
20 |
21 |
22 | /* ===== ZSTDERRORLIB_API : control library symbols visibility ===== */
23 | #ifndef ZSTDERRORLIB_VISIBILITY
24 | # if defined(__GNUC__) && (__GNUC__ >= 4)
25 | # define ZSTDERRORLIB_VISIBILITY __attribute__ ((visibility ("default")))
26 | # else
27 | # define ZSTDERRORLIB_VISIBILITY
28 | # endif
29 | #endif
30 | #if defined(ZSTD_DLL_EXPORT) && (ZSTD_DLL_EXPORT==1)
31 | # define ZSTDERRORLIB_API __declspec(dllexport) ZSTDERRORLIB_VISIBILITY
32 | #elif defined(ZSTD_DLL_IMPORT) && (ZSTD_DLL_IMPORT==1)
33 | # define ZSTDERRORLIB_API __declspec(dllimport) ZSTDERRORLIB_VISIBILITY /* It isn't required but allows to generate better code, saving a function pointer load from the IAT and an indirect jump.*/
34 | #else
35 | # define ZSTDERRORLIB_API ZSTDERRORLIB_VISIBILITY
36 | #endif
37 |
38 | /*-*********************************************
39 | * Error codes list
40 | *-*********************************************
41 | * Error codes _values_ are pinned down since v1.3.1 only.
42 | * Therefore, don't rely on values if you may link to any version < v1.3.1.
43 | *
44 | * Only values < 100 are considered stable.
45 | *
46 | * note 1 : this API shall be used with static linking only.
47 | * dynamic linking is not yet officially supported.
48 | * note 2 : Prefer relying on the enum than on its value whenever possible
49 | * This is the only supported way to use the error list < v1.3.1
50 | * note 3 : ZSTD_isError() is always correct, whatever the library version.
51 | **********************************************/
52 | typedef enum {
53 | ZSTD_error_no_error = 0,
54 | ZSTD_error_GENERIC = 1,
55 | ZSTD_error_prefix_unknown = 10,
56 | ZSTD_error_version_unsupported = 12,
57 | ZSTD_error_frameParameter_unsupported = 14,
58 | ZSTD_error_frameParameter_windowTooLarge = 16,
59 | ZSTD_error_corruption_detected = 20,
60 | ZSTD_error_checksum_wrong = 22,
61 | ZSTD_error_dictionary_corrupted = 30,
62 | ZSTD_error_dictionary_wrong = 32,
63 | ZSTD_error_dictionaryCreation_failed = 34,
64 | ZSTD_error_parameter_unsupported = 40,
65 | ZSTD_error_parameter_outOfBound = 42,
66 | ZSTD_error_tableLog_tooLarge = 44,
67 | ZSTD_error_maxSymbolValue_tooLarge = 46,
68 | ZSTD_error_maxSymbolValue_tooSmall = 48,
69 | ZSTD_error_stage_wrong = 60,
70 | ZSTD_error_init_missing = 62,
71 | ZSTD_error_memory_allocation = 64,
72 | ZSTD_error_workSpace_tooSmall= 66,
73 | ZSTD_error_dstSize_tooSmall = 70,
74 | ZSTD_error_srcSize_wrong = 72,
75 | ZSTD_error_dstBuffer_null = 74,
76 | /* following error codes are __NOT STABLE__, they can be removed or changed in future versions */
77 | ZSTD_error_frameIndex_tooLarge = 100,
78 | ZSTD_error_seekableIO = 102,
79 | ZSTD_error_dstBuffer_wrong = 104,
80 | ZSTD_error_srcBuffer_wrong = 105,
81 | ZSTD_error_maxCode = 120 /* never EVER use this value directly, it can change in future versions! Use ZSTD_isError() instead */
82 | } ZSTD_ErrorCode;
83 |
84 | /*! ZSTD_getErrorCode() :
85 | convert a `size_t` function result into a `ZSTD_ErrorCode` enum type,
86 | which can be used to compare with enum list published above */
87 | ZSTDERRORLIB_API ZSTD_ErrorCode ZSTD_getErrorCode(size_t functionResult);
88 | ZSTDERRORLIB_API const char* ZSTD_getErrorString(ZSTD_ErrorCode code); /**< Same as ZSTD_getErrorName, but using a `ZSTD_ErrorCode` enum argument */
89 |
90 |
91 | #if defined (__cplusplus)
92 | }
93 | #endif
94 |
95 | #endif /* ZSTD_ERRORS_H_398273423 */
96 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2016 Nolan O'Brien
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
23 |
--------------------------------------------------------------------------------
/Support/module.modulemap:
--------------------------------------------------------------------------------
1 | module ZipUtilities {
2 | umbrella header "ZipUtilities.h"
3 |
4 | export *
5 | module * { export * }
6 | }
7 |
--------------------------------------------------------------------------------
/ZipUtilities.podspec:
--------------------------------------------------------------------------------
1 | Pod::Spec.new do |s|
2 | s.name = "ZipUtilities"
3 | s.version = "1.13.0"
4 | s.summary = "Zip Archiving, Unarchiving and Utilities in Objective-C"
5 | s.description = <<-DESC
6 | ZipUtilities, prefixed with NOZ for Nolan O'Brien ZipUtilities, is a library of zipping and unzipping utilities for iOS and Mac OS X.
7 | DESC
8 | s.homepage = "https://github.com/NSProgrammer/ZipUtilities"
9 | s.license = { :type => "MIT", :file => "LICENSE" }
10 | s.author = "Nolan O'Brien"
11 | s.social_media_url = "https://twitter.com/NolanOBrien"
12 | s.ios.deployment_target = "6.0"
13 | s.osx.deployment_target = "10.9"
14 | s.source = { :git => "https://github.com/NSProgrammer/ZipUtilities.git", :tag => s.version }
15 | s.source_files = "ZipUtilities/*.{h,m}"
16 | s.exclude_files = "ZipUtilities/ZipUtilities.h", "ZipUtilities/*Info.plist"
17 | s.library = "z"
18 | s.requires_arc = true
19 | end
20 |
--------------------------------------------------------------------------------
/ZipUtilities.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/ZipUtilities.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDEDidComputeMac32BitWarning
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/ZipUtilities.xcodeproj/xcshareddata/xcschemes/ZipUtilitiesApp.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
37 |
38 |
39 |
40 |
41 |
42 |
52 |
54 |
60 |
61 |
62 |
63 |
69 |
71 |
77 |
78 |
79 |
80 |
82 |
83 |
86 |
87 |
88 |
--------------------------------------------------------------------------------
/ZipUtilities.xcodeproj/xcshareddata/xcschemes/libZipUtilities-mac.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
32 |
33 |
43 |
44 |
50 |
51 |
52 |
53 |
59 |
60 |
66 |
67 |
68 |
69 |
71 |
72 |
75 |
76 |
77 |
--------------------------------------------------------------------------------
/ZipUtilities.xcodeproj/xcshareddata/xcschemes/libbrotli-mac.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
32 |
33 |
43 |
44 |
50 |
51 |
52 |
53 |
59 |
60 |
66 |
67 |
68 |
69 |
71 |
72 |
75 |
76 |
77 |
--------------------------------------------------------------------------------
/ZipUtilities.xcodeproj/xcshareddata/xcschemes/libbrotli.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
32 |
33 |
43 |
44 |
50 |
51 |
52 |
53 |
59 |
60 |
66 |
67 |
68 |
69 |
71 |
72 |
75 |
76 |
77 |
--------------------------------------------------------------------------------
/ZipUtilities.xcodeproj/xcshareddata/xcschemes/libzstd-mac.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
32 |
33 |
43 |
44 |
50 |
51 |
52 |
53 |
59 |
60 |
66 |
67 |
68 |
69 |
71 |
72 |
75 |
76 |
77 |
--------------------------------------------------------------------------------
/ZipUtilities.xcodeproj/xcshareddata/xcschemes/libzstd.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
32 |
33 |
43 |
44 |
50 |
51 |
52 |
53 |
59 |
60 |
66 |
67 |
68 |
69 |
71 |
72 |
75 |
76 |
77 |
--------------------------------------------------------------------------------
/ZipUtilities/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | $(PRODUCT_BUNDLE_IDENTIFIER)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | FMWK
17 | CFBundleShortVersionString
18 | 1.13.0
19 | CFBundleSignature
20 | ????
21 | CFBundleVersion
22 | $(CURRENT_PROJECT_VERSION)
23 | NSPrincipalClass
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/ZipUtilities/NOZCompressionLibrary.h:
--------------------------------------------------------------------------------
1 | //
2 | // NOZCompressionLibrary.h
3 | // ZipUtilities
4 | //
5 | // The MIT License (MIT)
6 | //
7 | // Copyright (c) 2016 Nolan O'Brien
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in all
17 | // copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 | // SOFTWARE.
26 | //
27 |
28 |
29 | #import
30 |
31 | #import
32 |
33 | @protocol NOZDecoder;
34 | @protocol NOZEncoder;
35 |
36 | /**
37 | Library of encoders and decoders for __ZipUtilities__
38 | */
39 | @interface NOZCompressionLibrary : NSObject
40 |
41 | /** All the encoders */
42 | @property (atomic, nonnull, copy, readonly) NSDictionary> *allEncoders;
43 | /** all the decoders */
44 | @property (atomic, nonnull, copy, readonly) NSDictionary> *allDecoders;
45 |
46 | /** singleton accessor */
47 | + (nonnull instancetype)sharedInstance;
48 |
49 | /** unavailable */
50 | - (nonnull instancetype)init NS_UNAVAILABLE;
51 | /** unavailable */
52 | + (nonnull instancetype)new NS_UNAVAILABLE;
53 |
54 | /**
55 | Retrieve the compression encoder for a given method.
56 | Will return `nil` if nothing is registered.
57 | */
58 | - (nullable id)encoderForMethod:(NOZCompressionMethod)method;
59 | /**
60 | Retrieve the compression decoder for a given method.
61 | Will return `nil` if nothing is registered.
62 | */
63 | - (nullable id)decoderForMethod:(NOZCompressionMethod)method;
64 |
65 | /**
66 | Set the compression encoder for a given method.
67 | Setting `nil` will clear the encoder.
68 | Whatever encoder is registered for a given method will be used when _ZipUtilities_ compression occurs.
69 | */
70 | - (void)setEncoder:(nullable id)encoder forMethod:(NOZCompressionMethod)method;
71 | /**
72 | Set the compression decoder for a given method.
73 | Setting `nil` will clear the decoder.
74 | Whatever decoder is registered for a given method will be used when _ZipUtilities_ compression occurs.
75 | */
76 | - (void)setDecoder:(nullable id)decoder forMethod:(NOZCompressionMethod)method;
77 |
78 | @end
79 |
--------------------------------------------------------------------------------
/ZipUtilities/NOZDecoder.h:
--------------------------------------------------------------------------------
1 | //
2 | // NOZDecoder.h
3 | // ZipUtilities
4 | //
5 | // The MIT License (MIT)
6 | //
7 | // Copyright (c) 2016 Nolan O'Brien
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in all
17 | // copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 | // SOFTWARE.
26 | //
27 |
28 | #import
29 |
30 | #import
31 |
32 | /**
33 | Protocol for encapsulating the context and state of a decoding process.
34 | A context object must always be able to clean itself up on dealloc and should
35 | not rely on `finalize` to clean it up.
36 | */
37 | @protocol NOZDecoderContext
38 | /**
39 | return `YES` once if the decoding is known to have completed and
40 | any future call to decodeBytes will be a considered no-op (returning `YES`).
41 | If the decoder is provided a zero length buffer to decode, there is no more
42 | data to decode, but the decoder may continue decoding.
43 | The decoder will have it's decode method called until an error is encountered
44 | or hasFinished returns `YES`.
45 | */
46 | - (BOOL)hasFinished;
47 | @end
48 |
49 |
50 | /**
51 | Protocol to implement for constructing a compression decoder.
52 | */
53 | @protocol NOZDecoder
54 |
55 | /**
56 | Create a new context object to track the decoding process.
57 | @param flags The bit flags that were specefied for this encoder.
58 | @param callback The `NOZFlushCallback` that will be used to output the decompressed data
59 | @return the new context object
60 | */
61 | - (nonnull id)createContextForDecodingWithBitFlags:(UInt16)flags
62 | flushCallback:(nonnull NOZFlushCallback)callback;
63 |
64 | /**
65 | Initialize the decoding process.
66 | Call this first for each decoding process.
67 | If it succeeds, be sure to pair it with a call to `finalizeDecoderContext:error:`.
68 | */
69 | - (BOOL)initializeDecoderContext:(nonnull id)context;
70 |
71 | /**
72 | Decode the provided byte buffer.
73 | Call this as many times as necessary to get all bytes of a source decoded
74 | (or until a failure occurs).
75 | Can be provided zero _length_ if no more bytes to decode,
76 | but the _context_ still has `hasFinished` as `NO`
77 | */
78 | - (BOOL)decodeBytes:(nullable const Byte*)bytes
79 | length:(size_t)length
80 | context:(nonnull id)context;
81 |
82 | /**
83 | Finalize the decoding process.
84 | */
85 | - (BOOL)finalizeDecoderContext:(nonnull id)context;
86 |
87 | @end
88 |
--------------------------------------------------------------------------------
/ZipUtilities/NOZEncoder.h:
--------------------------------------------------------------------------------
1 | //
2 | // NOZEncoder.h
3 | // ZipUtilities
4 | //
5 | // The MIT License (MIT)
6 | //
7 | // Copyright (c) 2016 Nolan O'Brien
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in all
17 | // copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 | // SOFTWARE.
26 | //
27 |
28 | #import
29 |
30 | #import
31 |
32 | /**
33 | Protocol for encapsulating the context and state of an encoding process.
34 | A context object must always be able to clean itself up on dealloc and should
35 | not rely on `finalize` to clean it up.
36 | */
37 | @protocol NOZEncoderContext
38 | /** return `YES` if the encoded data was known to be text. `NO` otherwise. */
39 | - (BOOL)encodedDataWasText;
40 | @end
41 |
42 |
43 | /**
44 | Protocol to implement for constructing a compression encoder.
45 | */
46 | @protocol NOZEncoder
47 |
48 | /**
49 | Return any bit flags related to the given entry for hinting at the compression that will be used.
50 | */
51 | - (UInt16)bitFlagsForEntry:(nonnull id)entry;
52 |
53 | /**
54 | Create a new context object to track the encoding process.
55 | @param bitFlags The bit flags that were specified for this encoder.
56 | @param level The level of compression requested
57 | @param callback The `NOZFlushCallback` that will be used to output the compressed data
58 | @return the new context object
59 | */
60 | - (nonnull id)createContextWithBitFlags:(UInt16)bitFlags
61 | compressionLevel:(NOZCompressionLevel)level
62 | flushCallback:(nonnull NOZFlushCallback)callback;
63 |
64 | /**
65 | Initialize the encoding process.
66 | Call this first for each encoding process.
67 | If it succeeds, be sure to pair it with a call to `finalizeEncoderContext:`.
68 | */
69 | - (BOOL)initializeEncoderContext:(nonnull id)context;
70 |
71 | /**
72 | Encode the provided byte buffer.
73 | Call this as many times as necessary to get all bytes of a source encoded
74 | (or until a failure occurs).
75 | */
76 | - (BOOL)encodeBytes:(nonnull const Byte*)bytes
77 | length:(size_t)length
78 | context:(nonnull id)context;
79 |
80 | /**
81 | Finalize the encoding process.
82 | */
83 | - (BOOL)finalizeEncoderContext:(nonnull id)context;
84 |
85 | @optional
86 |
87 | /**
88 | (optional) Number of compression levels.
89 | If present, must return at least `1`.
90 | e.g. DEFLATE has 9 (1-9), Brotli has 12 (0-11), zstd has 22 (1-22 if you ignore the unused 0th)
91 | */
92 | - (NSUInteger)numberOfCompressionLevels;
93 |
94 | /**
95 | (optional) Value between `0` and `numberOfCompressionLevels` `- 1`
96 | Example: DEFLATE is levels 1 through 9 with default of 6, so the return value here would be `5`
97 | */
98 | - (NSUInteger)defaultCompressionLevel;
99 |
100 | @end
101 |
--------------------------------------------------------------------------------
/ZipUtilities/NOZUtils.h:
--------------------------------------------------------------------------------
1 | //
2 | // NOZUtils.h
3 | // ZipUtilities
4 | //
5 | // The MIT License (MIT)
6 | //
7 | // Copyright (c) 2016 Nolan O'Brien
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in all
17 | // copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 | // SOFTWARE.
26 | //
27 |
28 | #import
29 |
30 | @protocol NOZEncoder;
31 | @protocol NOZDecoder;
32 |
33 | //! Block for providing progress to. Used by `NOZCompressOperation` and `NOZDecompressOperation`.
34 | typedef void(^NOZProgressBlock)(int64_t totalBytes,
35 | int64_t bytesComplete,
36 | int64_t bytesCompletedThisPass,
37 | BOOL * __nonnull abort);
38 |
39 | //! Convenience function to compress a file without ZIP archive wrapping
40 | FOUNDATION_EXTERN BOOL NOZEncodeFile(NSString * __nonnull sourceFile,
41 | NSString * __nonnull destinationFile,
42 | id __nonnull encoder,
43 | NOZCompressionLevel level,
44 | NSError * __nullable * __nullable error);
45 |
46 | //! Convenience function to decompress a file without ZIP archive wrapping
47 | FOUNDATION_EXTERN BOOL NOZDecodeFile(NSString * __nonnull sourceFile,
48 | NSString * __nonnull destinationFile,
49 | id __nonnull decoder,
50 | NSError * __nullable * __nullable error);
51 |
52 | #pragma mark - Objective-C attribute support
53 |
54 | #if defined(__has_attribute) && (defined(__IPHONE_14_0) || defined(__MAC_10_16) || defined(__MAC_11_0))
55 | # define NOZ_SUPPORTS_OBJC_DIRECT __has_attribute(objc_direct)
56 | #else
57 | # define NOZ_SUPPORTS_OBJC_DIRECT 0
58 | #endif
59 |
60 | #pragma mark - Objective-C Direct Support
61 |
62 | #if NOZ_SUPPORTS_OBJC_DIRECT
63 | # define NOZ_OBJC_DIRECT __attribute__((objc_direct))
64 | # define NOZ_OBJC_DIRECT_MEMBERS __attribute__((objc_direct_members))
65 | #else
66 | # define NOZ_OBJC_DIRECT
67 | # define NOZ_OBJC_DIRECT_MEMBERS
68 | #endif // #if NOZ_SUPPORTS_OBJC_DIRECT
69 |
--------------------------------------------------------------------------------
/ZipUtilities/NOZ_Project.h:
--------------------------------------------------------------------------------
1 | //
2 | // NOZ_Project.h
3 | // ZipUtilities
4 | //
5 | // The MIT License (MIT)
6 | //
7 | // Copyright (c) 2016 Nolan O'Brien
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in all
17 | // copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 | // SOFTWARE.
26 | //
27 |
28 | #import
29 |
30 | #pragma mark Utils
31 |
32 | /**
33 | `noz_macro_concat`
34 | Macro for combining 2 names into a single name.
35 | Offers the ability to expand any initial macros passed in.
36 |
37 | *Example:*
38 |
39 | // writing this:
40 | int noz_macro_concat(hidden_int_, __FILE__) = __FILE__;
41 | // will be preprocessed as this:
42 | int hidden_int_38 = 38;
43 |
44 | */
45 | #define _noz_macro_concat(a, b) a##b
46 | #define noz_macro_concat(a, b) _noz_macro_concat(a, b)
47 |
48 | #define NOZBufferSize() (4 * NSPageSize())
49 |
50 | #pragma mark Defer Support
51 |
52 | /**
53 | `noz_defer`
54 | Macro for support code deferral.
55 | Offers the same behavior as `defer` in Swift.
56 | Effectively, the block provided to `noz_defer` will execute on scope exit.
57 | Offers a safe way to perform cleanup on scope exit, no matter the mechanism.
58 | Scope exits include: break, continue, return, @throw/throw and leaving the scope of an if/else/while/for
59 |
60 | *Example:*
61 |
62 | FILE *file = fopen(fileStr);
63 | noz_defer(^{ fclose(file); });
64 | ... work ...
65 | if (some failure) {
66 | return NO; // fclose will auto happen
67 | }
68 | ... more work ...
69 | // complete
70 | return YES; // fclose will auto happen
71 | */
72 | #define noz_defer(deferBlock) \
73 | noz_defer_block_t noz_macro_concat(__noz_stack_defer_block_, __LINE__) __attribute__((cleanup(noz_deferFunc), unused)) = deferBlock
74 |
75 | typedef void(^noz_defer_block_t)(void);
76 | NS_INLINE void noz_deferFunc(noz_defer_block_t __nonnull NS_NOESCAPE * __nonnull blockRef)
77 | {
78 | noz_defer_block_t actualBlock = *blockRef;
79 | actualBlock();
80 | }
81 |
82 | #pragma mark DOS Time
83 |
84 | FOUNDATION_EXTERN void noz_dos_date_from_NSDate(NSDate *__nullable dateObject,
85 | UInt16*__nonnull dateOut,
86 | UInt16*__nonnull timeOut);
87 | FOUNDATION_EXTERN NSDate * __nullable noz_NSDate_from_dos_date(UInt16 dosDate,
88 | UInt16 dosTime);
89 |
90 | #pragma mark CRC32 exposed
91 |
92 | NS_ASSUME_NONNULL_BEGIN
93 |
94 | extern unsigned long crc32(unsigned long crc,
95 | const unsigned char *buf,
96 | unsigned int len);
97 |
98 | NS_ASSUME_NONNULL_END
99 |
--------------------------------------------------------------------------------
/ZipUtilities/NSData+NOZAdditions.h:
--------------------------------------------------------------------------------
1 | //
2 | // NSData+NOZAdditions.h
3 | // ZipUtilities
4 | //
5 | // The MIT License (MIT)
6 | //
7 | // Copyright (c) 2016 Nolan O'Brien
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in all
17 | // copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 | // SOFTWARE.
26 | //
27 |
28 | #import
29 |
30 | #import
31 |
32 | @protocol NOZEncoder;
33 | @protocol NOZDecoder;
34 |
35 | /**
36 | Convenience category on `NSData` to permit easy compressing/decompressing of `NSData` to `NSData`
37 | */
38 | @interface NSData (NOZAdditions)
39 |
40 | /**
41 | Compress the receiver
42 | @param encoder the `NOZEncoder` to compress with
43 | @param compressionLevel the level to compress at (if supported by the _encoder_)
44 | @return The compressed data or `nil` if an error was encountered
45 | */
46 | - (nullable NSData *)noz_dataByCompressing:(nonnull id)encoder
47 | compressionLevel:(NOZCompressionLevel)compressionLevel;
48 |
49 | /**
50 | Decompress the receiver
51 | @param decoder the `NOZDecoder` to decompress with
52 | @return The decompressed data or `nil` if an error was encountered
53 | */
54 | - (nullable NSData *)noz_dataByDecompressing:(nonnull id)decoder;
55 |
56 | @end
57 |
--------------------------------------------------------------------------------
/ZipUtilities/NSStream+NOZAdditions.h:
--------------------------------------------------------------------------------
1 | //
2 | // NSStream+NOZAdditions.h
3 | // ZipUtilities
4 | //
5 | // The MIT License (MIT)
6 | //
7 | // Copyright (c) 2016 Nolan O'Brien
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in all
17 | // copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 | // SOFTWARE.
26 | //
27 |
28 | #import
29 |
30 | #import
31 |
32 | @protocol NOZEncoder;
33 | @protocol NOZDecoder;
34 |
35 | /**
36 | Category for __ZipUtilities__ specific convenience methods
37 | */
38 | @interface NSInputStream (NOZAdditions)
39 |
40 | /**
41 | Create a stream that compresses it's bytes as they are read. Useful for something like an `NSURLConnection`'s `NSURLRequest` or an `NSURLSessionUploadTask` that provide an `NSInputStream`.
42 | @param stream The uncompressed `NSInputStream` to wrap
43 | @param encoder The encoder to use for compressing (often best to use `NOZEncoderForCompressionMethod` to get an encoder)
44 | @param compressionLevel The level at which to compress (if supported by the _encoder_).
45 | @return an `NSInputStream` that compressed it's wrapped _stream_ as bytes are read.
46 | NOTE: The implementation of the wrapping `NSInputStream` could probably be further optimized.
47 | */
48 | + (nonnull NSInputStream *)noz_compressedInputStream:(nonnull NSInputStream *)stream
49 | withEncoder:(nonnull id)encoder
50 | compressionLevel:(NOZCompressionLevel)compressionLevel;
51 |
52 | @end
53 |
54 | /**
55 | Category for __ZipUtilities__ specific convenience methods
56 | */
57 | @interface NSStream (NOZAdditions)
58 |
59 | /**
60 | Convenience method to acquire a pair of bount `NSInputStream` and `NSOutputStream` streams.
61 | Code comes directly from Apple sample code:
62 | https://developer.apple.com/library/ios/samplecode/SimpleURLConnections/Listings/PostController_m.html
63 | */
64 | + (void)noz_createBoundInputStream:(NSInputStream * __nonnull * __nullable)inputStreamPtr
65 | outputStream:(NSOutputStream * __nonnull * __nullable)outputStreamPtr
66 | bufferSize:(NSUInteger)bufferSize;
67 |
68 | @end
69 |
--------------------------------------------------------------------------------
/ZipUtilities/OSX-Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | $(PRODUCT_BUNDLE_IDENTIFIER)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | FMWK
17 | CFBundleShortVersionString
18 | 1.13.0
19 | CFBundleSignature
20 | ????
21 | CFBundleVersion
22 | $(CURRENT_PROJECT_VERSION)
23 | NSHumanReadableCopyright
24 | Copyright © 2015 NSProgrammer. All rights reserved.
25 | NSPrincipalClass
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/ZipUtilities/ZipUtilities.h:
--------------------------------------------------------------------------------
1 | //
2 | // ZipUtilities.h
3 | // ZipUtilities
4 | //
5 | // The MIT License (MIT)
6 | //
7 | // Copyright (c) 2016 Nolan O'Brien
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in all
17 | // copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 | // SOFTWARE.
26 | //
27 |
28 | #import
29 | #import
30 | #import
31 | #import
32 | #import
33 | #import
34 | #import
35 | #import
36 | #import
37 | #import
38 | #import
39 | #import
40 |
41 | #import
42 | #import
43 |
--------------------------------------------------------------------------------
/ZipUtilitiesApp/AppDelegate.h:
--------------------------------------------------------------------------------
1 | //
2 | // AppDelegate.h
3 | // ZipUtilitiesApp
4 | //
5 | // Created by Nolan O'Brien on 11/16/16.
6 | // Copyright © 2016 NSProgrammer. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface AppDelegate : UIResponder
12 | @property (strong, nonatomic) UIWindow *window;
13 | @end
14 |
15 |
--------------------------------------------------------------------------------
/ZipUtilitiesApp/AppDelegate.m:
--------------------------------------------------------------------------------
1 | //
2 | // AppDelegate.m
3 | // ZipUtilitiesApp
4 | //
5 | // Created by Nolan O'Brien on 11/16/16.
6 | // Copyright © 2016 NSProgrammer. All rights reserved.
7 | //
8 |
9 | #import "AppDelegate.h"
10 | #import "ViewController.h"
11 |
12 | @interface AppDelegate ()
13 | @end
14 |
15 | @implementation AppDelegate
16 |
17 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
18 | {
19 | UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:[[ViewController alloc] init]];
20 | UIWindow *window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
21 | self.window = window;
22 | self.window.rootViewController = navController;
23 | [self.window makeKeyAndVisible];
24 | return YES;
25 | }
26 |
27 | @end
28 |
--------------------------------------------------------------------------------
/ZipUtilitiesApp/Assets.xcassets/AppIcon.appiconset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "iphone",
5 | "size" : "20x20",
6 | "scale" : "2x"
7 | },
8 | {
9 | "idiom" : "iphone",
10 | "size" : "20x20",
11 | "scale" : "3x"
12 | },
13 | {
14 | "idiom" : "iphone",
15 | "size" : "29x29",
16 | "scale" : "2x"
17 | },
18 | {
19 | "idiom" : "iphone",
20 | "size" : "29x29",
21 | "scale" : "3x"
22 | },
23 | {
24 | "idiom" : "iphone",
25 | "size" : "40x40",
26 | "scale" : "2x"
27 | },
28 | {
29 | "idiom" : "iphone",
30 | "size" : "40x40",
31 | "scale" : "3x"
32 | },
33 | {
34 | "idiom" : "iphone",
35 | "size" : "60x60",
36 | "scale" : "2x"
37 | },
38 | {
39 | "idiom" : "iphone",
40 | "size" : "60x60",
41 | "scale" : "3x"
42 | }
43 | ],
44 | "info" : {
45 | "version" : 1,
46 | "author" : "xcode"
47 | }
48 | }
--------------------------------------------------------------------------------
/ZipUtilitiesApp/Base.lproj/LaunchScreen.storyboard:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/ZipUtilitiesApp/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | $(PRODUCT_BUNDLE_IDENTIFIER)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | APPL
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleVersion
20 | 1
21 | LSRequiresIPhoneOS
22 |
23 | UILaunchStoryboardName
24 | LaunchScreen
25 | UIRequiredDeviceCapabilities
26 |
27 | armv7
28 |
29 | UISupportedInterfaceOrientations
30 |
31 | UIInterfaceOrientationPortrait
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/ZipUtilitiesApp/ViewController.h:
--------------------------------------------------------------------------------
1 | //
2 | // ViewController.h
3 | // ZipUtilitiesApp
4 | //
5 | // Created by Nolan O'Brien on 11/16/16.
6 | // Copyright © 2016 NSProgrammer. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface ViewController : UIViewController
12 | @end
13 |
14 |
--------------------------------------------------------------------------------
/ZipUtilitiesApp/main.m:
--------------------------------------------------------------------------------
1 | //
2 | // main.m
3 | // ZipUtilitiesApp
4 | //
5 | // Created by Nolan O'Brien on 11/16/16.
6 | // Copyright © 2016 NSProgrammer. All rights reserved.
7 | //
8 |
9 | #import
10 | #import "AppDelegate.h"
11 |
12 | int main(int argc, char * argv[]) {
13 | @autoreleasepool {
14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/ZipUtilitiesTests/Aesop_cp437.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NSProgrammer/ZipUtilities/7152d58805eaf332ca24b8f460e4074b7ce32216/ZipUtilitiesTests/Aesop_cp437.zip
--------------------------------------------------------------------------------
/ZipUtilitiesTests/Bad_File.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NSProgrammer/ZipUtilities/7152d58805eaf332ca24b8f460e4074b7ce32216/ZipUtilitiesTests/Bad_File.zip
--------------------------------------------------------------------------------
/ZipUtilitiesTests/Data.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NSProgrammer/ZipUtilities/7152d58805eaf332ca24b8f460e4074b7ce32216/ZipUtilitiesTests/Data.zip
--------------------------------------------------------------------------------
/ZipUtilitiesTests/Directory.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NSProgrammer/ZipUtilities/7152d58805eaf332ca24b8f460e4074b7ce32216/ZipUtilitiesTests/Directory.zip
--------------------------------------------------------------------------------
/ZipUtilitiesTests/File.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NSProgrammer/ZipUtilities/7152d58805eaf332ca24b8f460e4074b7ce32216/ZipUtilitiesTests/File.zip
--------------------------------------------------------------------------------
/ZipUtilitiesTests/File2.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NSProgrammer/ZipUtilities/7152d58805eaf332ca24b8f460e4074b7ce32216/ZipUtilitiesTests/File2.zip
--------------------------------------------------------------------------------
/ZipUtilitiesTests/FrameworkTests-Bridging-Header.h:
--------------------------------------------------------------------------------
1 | //
2 | // Use this file to import your target's public headers that you would like to expose to Swift.
3 | //
4 |
5 | #import "NOZXAppleCompressionCoder.h"
6 | #import "NOZXBrotliCompressionCoder.h"
7 | #import "NOZXZStandardCompressionCoder.h"
8 |
--------------------------------------------------------------------------------
/ZipUtilitiesTests/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | $(PRODUCT_BUNDLE_IDENTIFIER)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | BNDL
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleSignature
20 | ????
21 | CFBundleVersion
22 | 1
23 |
24 |
25 |
--------------------------------------------------------------------------------
/ZipUtilitiesTests/Mixed.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NSProgrammer/ZipUtilities/7152d58805eaf332ca24b8f460e4074b7ce32216/ZipUtilitiesTests/Mixed.zip
--------------------------------------------------------------------------------
/ZipUtilitiesTests/Star.Wars.7.Trailer.mp4:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NSProgrammer/ZipUtilities/7152d58805eaf332ca24b8f460e4074b7ce32216/ZipUtilitiesTests/Star.Wars.7.Trailer.mp4
--------------------------------------------------------------------------------
/ZipUtilitiesTests/Star.Wars.7.Trailer.mp4.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NSProgrammer/ZipUtilities/7152d58805eaf332ca24b8f460e4074b7ce32216/ZipUtilitiesTests/Star.Wars.7.Trailer.mp4.zip
--------------------------------------------------------------------------------
/ZipUtilitiesTests/book.zstd_dict:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NSProgrammer/ZipUtilities/7152d58805eaf332ca24b8f460e4074b7ce32216/ZipUtilitiesTests/book.zstd_dict
--------------------------------------------------------------------------------
/ZipUtilitiesTests/htl.1024.zstd_dict:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NSProgrammer/ZipUtilities/7152d58805eaf332ca24b8f460e4074b7ce32216/ZipUtilitiesTests/htl.1024.zstd_dict
--------------------------------------------------------------------------------
/ZipUtilitiesTests/htl.128.zstd_dict:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NSProgrammer/ZipUtilities/7152d58805eaf332ca24b8f460e4074b7ce32216/ZipUtilitiesTests/htl.128.zstd_dict
--------------------------------------------------------------------------------
/ZipUtilitiesTests/htl.256.zstd_dict:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NSProgrammer/ZipUtilities/7152d58805eaf332ca24b8f460e4074b7ce32216/ZipUtilitiesTests/htl.256.zstd_dict
--------------------------------------------------------------------------------
/ZipUtilitiesTests/htl.512.zstd_dict:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NSProgrammer/ZipUtilities/7152d58805eaf332ca24b8f460e4074b7ce32216/ZipUtilitiesTests/htl.512.zstd_dict
--------------------------------------------------------------------------------
/ZipUtilitiesTests/maniac-mansion/Game/00.LFL:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NSProgrammer/ZipUtilities/7152d58805eaf332ca24b8f460e4074b7ce32216/ZipUtilitiesTests/maniac-mansion/Game/00.LFL
--------------------------------------------------------------------------------
/ZipUtilitiesTests/maniac-mansion/Game/01.LFL:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NSProgrammer/ZipUtilities/7152d58805eaf332ca24b8f460e4074b7ce32216/ZipUtilitiesTests/maniac-mansion/Game/01.LFL
--------------------------------------------------------------------------------
/ZipUtilitiesTests/maniac-mansion/Game/02.LFL:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NSProgrammer/ZipUtilities/7152d58805eaf332ca24b8f460e4074b7ce32216/ZipUtilitiesTests/maniac-mansion/Game/02.LFL
--------------------------------------------------------------------------------
/ZipUtilitiesTests/maniac-mansion/Game/03.LFL:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NSProgrammer/ZipUtilities/7152d58805eaf332ca24b8f460e4074b7ce32216/ZipUtilitiesTests/maniac-mansion/Game/03.LFL
--------------------------------------------------------------------------------
/ZipUtilitiesTests/maniac-mansion/Game/04.LFL:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NSProgrammer/ZipUtilities/7152d58805eaf332ca24b8f460e4074b7ce32216/ZipUtilitiesTests/maniac-mansion/Game/04.LFL
--------------------------------------------------------------------------------
/ZipUtilitiesTests/maniac-mansion/Game/05.LFL:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NSProgrammer/ZipUtilities/7152d58805eaf332ca24b8f460e4074b7ce32216/ZipUtilitiesTests/maniac-mansion/Game/05.LFL
--------------------------------------------------------------------------------
/ZipUtilitiesTests/maniac-mansion/Game/06.LFL:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NSProgrammer/ZipUtilities/7152d58805eaf332ca24b8f460e4074b7ce32216/ZipUtilitiesTests/maniac-mansion/Game/06.LFL
--------------------------------------------------------------------------------
/ZipUtilitiesTests/maniac-mansion/Game/07.LFL:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NSProgrammer/ZipUtilities/7152d58805eaf332ca24b8f460e4074b7ce32216/ZipUtilitiesTests/maniac-mansion/Game/07.LFL
--------------------------------------------------------------------------------
/ZipUtilitiesTests/maniac-mansion/Game/08.LFL:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NSProgrammer/ZipUtilities/7152d58805eaf332ca24b8f460e4074b7ce32216/ZipUtilitiesTests/maniac-mansion/Game/08.LFL
--------------------------------------------------------------------------------
/ZipUtilitiesTests/maniac-mansion/Game/09.LFL:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NSProgrammer/ZipUtilities/7152d58805eaf332ca24b8f460e4074b7ce32216/ZipUtilitiesTests/maniac-mansion/Game/09.LFL
--------------------------------------------------------------------------------
/ZipUtilitiesTests/maniac-mansion/Game/10.LFL:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NSProgrammer/ZipUtilities/7152d58805eaf332ca24b8f460e4074b7ce32216/ZipUtilitiesTests/maniac-mansion/Game/10.LFL
--------------------------------------------------------------------------------
/ZipUtilitiesTests/maniac-mansion/Game/11.LFL:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NSProgrammer/ZipUtilities/7152d58805eaf332ca24b8f460e4074b7ce32216/ZipUtilitiesTests/maniac-mansion/Game/11.LFL
--------------------------------------------------------------------------------
/ZipUtilitiesTests/maniac-mansion/Game/12.LFL:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NSProgrammer/ZipUtilities/7152d58805eaf332ca24b8f460e4074b7ce32216/ZipUtilitiesTests/maniac-mansion/Game/12.LFL
--------------------------------------------------------------------------------
/ZipUtilitiesTests/maniac-mansion/Game/13.LFL:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NSProgrammer/ZipUtilities/7152d58805eaf332ca24b8f460e4074b7ce32216/ZipUtilitiesTests/maniac-mansion/Game/13.LFL
--------------------------------------------------------------------------------
/ZipUtilitiesTests/maniac-mansion/Game/14.LFL:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NSProgrammer/ZipUtilities/7152d58805eaf332ca24b8f460e4074b7ce32216/ZipUtilitiesTests/maniac-mansion/Game/14.LFL
--------------------------------------------------------------------------------
/ZipUtilitiesTests/maniac-mansion/Game/15.LFL:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NSProgrammer/ZipUtilities/7152d58805eaf332ca24b8f460e4074b7ce32216/ZipUtilitiesTests/maniac-mansion/Game/15.LFL
--------------------------------------------------------------------------------
/ZipUtilitiesTests/maniac-mansion/Game/16.LFL:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NSProgrammer/ZipUtilities/7152d58805eaf332ca24b8f460e4074b7ce32216/ZipUtilitiesTests/maniac-mansion/Game/16.LFL
--------------------------------------------------------------------------------
/ZipUtilitiesTests/maniac-mansion/Game/17.LFL:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NSProgrammer/ZipUtilities/7152d58805eaf332ca24b8f460e4074b7ce32216/ZipUtilitiesTests/maniac-mansion/Game/17.LFL
--------------------------------------------------------------------------------
/ZipUtilitiesTests/maniac-mansion/Game/18.LFL:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NSProgrammer/ZipUtilities/7152d58805eaf332ca24b8f460e4074b7ce32216/ZipUtilitiesTests/maniac-mansion/Game/18.LFL
--------------------------------------------------------------------------------
/ZipUtilitiesTests/maniac-mansion/Game/19.LFL:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NSProgrammer/ZipUtilities/7152d58805eaf332ca24b8f460e4074b7ce32216/ZipUtilitiesTests/maniac-mansion/Game/19.LFL
--------------------------------------------------------------------------------
/ZipUtilitiesTests/maniac-mansion/Game/20.LFL:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NSProgrammer/ZipUtilities/7152d58805eaf332ca24b8f460e4074b7ce32216/ZipUtilitiesTests/maniac-mansion/Game/20.LFL
--------------------------------------------------------------------------------
/ZipUtilitiesTests/maniac-mansion/Game/21.LFL:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NSProgrammer/ZipUtilities/7152d58805eaf332ca24b8f460e4074b7ce32216/ZipUtilitiesTests/maniac-mansion/Game/21.LFL
--------------------------------------------------------------------------------
/ZipUtilitiesTests/maniac-mansion/Game/22.LFL:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NSProgrammer/ZipUtilities/7152d58805eaf332ca24b8f460e4074b7ce32216/ZipUtilitiesTests/maniac-mansion/Game/22.LFL
--------------------------------------------------------------------------------
/ZipUtilitiesTests/maniac-mansion/Game/23.LFL:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NSProgrammer/ZipUtilities/7152d58805eaf332ca24b8f460e4074b7ce32216/ZipUtilitiesTests/maniac-mansion/Game/23.LFL
--------------------------------------------------------------------------------
/ZipUtilitiesTests/maniac-mansion/Game/24.LFL:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NSProgrammer/ZipUtilities/7152d58805eaf332ca24b8f460e4074b7ce32216/ZipUtilitiesTests/maniac-mansion/Game/24.LFL
--------------------------------------------------------------------------------
/ZipUtilitiesTests/maniac-mansion/Game/25.LFL:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NSProgrammer/ZipUtilities/7152d58805eaf332ca24b8f460e4074b7ce32216/ZipUtilitiesTests/maniac-mansion/Game/25.LFL
--------------------------------------------------------------------------------
/ZipUtilitiesTests/maniac-mansion/Game/26.LFL:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NSProgrammer/ZipUtilities/7152d58805eaf332ca24b8f460e4074b7ce32216/ZipUtilitiesTests/maniac-mansion/Game/26.LFL
--------------------------------------------------------------------------------
/ZipUtilitiesTests/maniac-mansion/Game/27.LFL:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NSProgrammer/ZipUtilities/7152d58805eaf332ca24b8f460e4074b7ce32216/ZipUtilitiesTests/maniac-mansion/Game/27.LFL
--------------------------------------------------------------------------------
/ZipUtilitiesTests/maniac-mansion/Game/28.LFL:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NSProgrammer/ZipUtilities/7152d58805eaf332ca24b8f460e4074b7ce32216/ZipUtilitiesTests/maniac-mansion/Game/28.LFL
--------------------------------------------------------------------------------
/ZipUtilitiesTests/maniac-mansion/Game/29.LFL:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NSProgrammer/ZipUtilities/7152d58805eaf332ca24b8f460e4074b7ce32216/ZipUtilitiesTests/maniac-mansion/Game/29.LFL
--------------------------------------------------------------------------------
/ZipUtilitiesTests/maniac-mansion/Game/30.LFL:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NSProgrammer/ZipUtilities/7152d58805eaf332ca24b8f460e4074b7ce32216/ZipUtilitiesTests/maniac-mansion/Game/30.LFL
--------------------------------------------------------------------------------
/ZipUtilitiesTests/maniac-mansion/Game/31.LFL:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NSProgrammer/ZipUtilities/7152d58805eaf332ca24b8f460e4074b7ce32216/ZipUtilitiesTests/maniac-mansion/Game/31.LFL
--------------------------------------------------------------------------------
/ZipUtilitiesTests/maniac-mansion/Game/32.LFL:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NSProgrammer/ZipUtilities/7152d58805eaf332ca24b8f460e4074b7ce32216/ZipUtilitiesTests/maniac-mansion/Game/32.LFL
--------------------------------------------------------------------------------
/ZipUtilitiesTests/maniac-mansion/Game/33.LFL:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NSProgrammer/ZipUtilities/7152d58805eaf332ca24b8f460e4074b7ce32216/ZipUtilitiesTests/maniac-mansion/Game/33.LFL
--------------------------------------------------------------------------------
/ZipUtilitiesTests/maniac-mansion/Game/34.LFL:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NSProgrammer/ZipUtilities/7152d58805eaf332ca24b8f460e4074b7ce32216/ZipUtilitiesTests/maniac-mansion/Game/34.LFL
--------------------------------------------------------------------------------
/ZipUtilitiesTests/maniac-mansion/Game/35.LFL:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NSProgrammer/ZipUtilities/7152d58805eaf332ca24b8f460e4074b7ce32216/ZipUtilitiesTests/maniac-mansion/Game/35.LFL
--------------------------------------------------------------------------------
/ZipUtilitiesTests/maniac-mansion/Game/36.LFL:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NSProgrammer/ZipUtilities/7152d58805eaf332ca24b8f460e4074b7ce32216/ZipUtilitiesTests/maniac-mansion/Game/36.LFL
--------------------------------------------------------------------------------
/ZipUtilitiesTests/maniac-mansion/Game/37.LFL:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NSProgrammer/ZipUtilities/7152d58805eaf332ca24b8f460e4074b7ce32216/ZipUtilitiesTests/maniac-mansion/Game/37.LFL
--------------------------------------------------------------------------------
/ZipUtilitiesTests/maniac-mansion/Game/38.LFL:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NSProgrammer/ZipUtilities/7152d58805eaf332ca24b8f460e4074b7ce32216/ZipUtilitiesTests/maniac-mansion/Game/38.LFL
--------------------------------------------------------------------------------
/ZipUtilitiesTests/maniac-mansion/Game/39.LFL:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NSProgrammer/ZipUtilities/7152d58805eaf332ca24b8f460e4074b7ce32216/ZipUtilitiesTests/maniac-mansion/Game/39.LFL
--------------------------------------------------------------------------------
/ZipUtilitiesTests/maniac-mansion/Game/40.LFL:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NSProgrammer/ZipUtilities/7152d58805eaf332ca24b8f460e4074b7ce32216/ZipUtilitiesTests/maniac-mansion/Game/40.LFL
--------------------------------------------------------------------------------
/ZipUtilitiesTests/maniac-mansion/Game/41.LFL:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NSProgrammer/ZipUtilities/7152d58805eaf332ca24b8f460e4074b7ce32216/ZipUtilitiesTests/maniac-mansion/Game/41.LFL
--------------------------------------------------------------------------------
/ZipUtilitiesTests/maniac-mansion/Game/42.LFL:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NSProgrammer/ZipUtilities/7152d58805eaf332ca24b8f460e4074b7ce32216/ZipUtilitiesTests/maniac-mansion/Game/42.LFL
--------------------------------------------------------------------------------
/ZipUtilitiesTests/maniac-mansion/Game/43.LFL:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NSProgrammer/ZipUtilities/7152d58805eaf332ca24b8f460e4074b7ce32216/ZipUtilitiesTests/maniac-mansion/Game/43.LFL
--------------------------------------------------------------------------------
/ZipUtilitiesTests/maniac-mansion/Game/44.LFL:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NSProgrammer/ZipUtilities/7152d58805eaf332ca24b8f460e4074b7ce32216/ZipUtilitiesTests/maniac-mansion/Game/44.LFL
--------------------------------------------------------------------------------
/ZipUtilitiesTests/maniac-mansion/Game/45.LFL:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NSProgrammer/ZipUtilities/7152d58805eaf332ca24b8f460e4074b7ce32216/ZipUtilitiesTests/maniac-mansion/Game/45.LFL
--------------------------------------------------------------------------------
/ZipUtilitiesTests/maniac-mansion/Game/46.LFL:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NSProgrammer/ZipUtilities/7152d58805eaf332ca24b8f460e4074b7ce32216/ZipUtilitiesTests/maniac-mansion/Game/46.LFL
--------------------------------------------------------------------------------
/ZipUtilitiesTests/maniac-mansion/Game/47.LFL:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NSProgrammer/ZipUtilities/7152d58805eaf332ca24b8f460e4074b7ce32216/ZipUtilitiesTests/maniac-mansion/Game/47.LFL
--------------------------------------------------------------------------------
/ZipUtilitiesTests/maniac-mansion/Game/48.LFL:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NSProgrammer/ZipUtilities/7152d58805eaf332ca24b8f460e4074b7ce32216/ZipUtilitiesTests/maniac-mansion/Game/48.LFL
--------------------------------------------------------------------------------
/ZipUtilitiesTests/maniac-mansion/Game/49.LFL:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NSProgrammer/ZipUtilities/7152d58805eaf332ca24b8f460e4074b7ce32216/ZipUtilitiesTests/maniac-mansion/Game/49.LFL
--------------------------------------------------------------------------------
/ZipUtilitiesTests/maniac-mansion/Game/50.LFL:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NSProgrammer/ZipUtilities/7152d58805eaf332ca24b8f460e4074b7ce32216/ZipUtilitiesTests/maniac-mansion/Game/50.LFL
--------------------------------------------------------------------------------
/ZipUtilitiesTests/maniac-mansion/Game/51.LFL:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NSProgrammer/ZipUtilities/7152d58805eaf332ca24b8f460e4074b7ce32216/ZipUtilitiesTests/maniac-mansion/Game/51.LFL
--------------------------------------------------------------------------------
/ZipUtilitiesTests/maniac-mansion/Game/52.LFL:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NSProgrammer/ZipUtilities/7152d58805eaf332ca24b8f460e4074b7ce32216/ZipUtilitiesTests/maniac-mansion/Game/52.LFL
--------------------------------------------------------------------------------
/ZipUtilitiesTests/maniac-mansion/Game/MANIAC.EXE:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NSProgrammer/ZipUtilities/7152d58805eaf332ca24b8f460e4074b7ce32216/ZipUtilitiesTests/maniac-mansion/Game/MANIAC.EXE
--------------------------------------------------------------------------------
/ZipUtilitiesTests/maniac-mansion/ca1.jpeg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NSProgrammer/ZipUtilities/7152d58805eaf332ca24b8f460e4074b7ce32216/ZipUtilitiesTests/maniac-mansion/ca1.jpeg
--------------------------------------------------------------------------------
/noz/NOZCLI.h:
--------------------------------------------------------------------------------
1 | //
2 | // NOZCLI.h
3 | // ZipUtilities
4 | //
5 | // Created by Nolan O'Brien on 5/7/17.
6 | // Copyright © 2017 NSProgrammer. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | #import
12 |
13 | @class MethodInfo;
14 |
15 | FOUNDATION_EXTERN int NOZCLI_main(NSString *exe,
16 | NSString *exeDir,
17 | NSString *currentDir,
18 | NSArray *args);
19 | FOUNDATION_EXTERN void NOZCLI_printUsage(NSString *exe, NSString *modeFlag);
20 |
21 | FOUNDATION_EXTERN void NOZCLI_registerExtraEncoders(void);
22 |
23 | FOUNDATION_EXTERN void NOZCLI_printError(NSError *error);
24 | FOUNDATION_EXTERN NSString *NOZCLI_normalizedPath(NSString *envPath, NSString *fileArg);
25 | FOUNDATION_EXTERN double NOZCLI_computeCompressionRatio(long long uncompressedBytes, long long compressedBytes);
26 |
27 | FOUNDATION_EXTERN MethodInfo *NOZCLI_lookupMethod(NOZCompressionMethod method);
28 | FOUNDATION_EXTERN MethodInfo *NOZCLI_lookupMethodByName(NSString *method);
29 |
30 | FOUNDATION_EXTERN NSArray *NOZCLI_allMethods(void);
31 | FOUNDATION_EXTERN NSArray *NOZCLI_allUnsupportedMethods(void);
32 | FOUNDATION_EXTERN NSArray *NOZCLI_allDefaultMethods(void);
33 | FOUNDATION_EXTERN NSArray *NOZCLI_allExtendedMethods(void);
34 | FOUNDATION_EXTERN BOOL NOZCLI_registerMethodToNumberMap(NSDictionary *methodToNumberMap);
35 |
36 | FOUNDATION_EXTERN NSArray *NOZCLI_allModes(void);
37 |
38 | @interface MethodInfo : NSObject
39 |
40 | @property (nonatomic, copy, readonly) NSString *name;
41 | @property (nonatomic, readonly) NOZCompressionMethod method;
42 | @property (nonatomic, readonly) NSUInteger levels;
43 | @property (nonatomic, readonly) NSUInteger defaultLevel;
44 |
45 | @property (nonatomic, readonly) id encoder;
46 | @property (nonatomic, readonly) id decoder;
47 | @property (nonatomic, readonly, getter=isDefaultCodec) BOOL defaultCodec;
48 |
49 | - (instancetype)init NS_UNAVAILABLE;
50 | + (instancetype)new NS_UNAVAILABLE;
51 |
52 | @end
53 |
--------------------------------------------------------------------------------
/noz/NOZCLICompressMode.h:
--------------------------------------------------------------------------------
1 | //
2 | // NOZCLICompressMode.h
3 | // ZipUtilities
4 | //
5 | // Created by Nolan O'Brien on 5/7/17.
6 | // Copyright © 2017 NSProgrammer. All rights reserved.
7 | //
8 |
9 | #import "NOZCLIModeProtocol.h"
10 |
11 | @interface NOZCLICompressModeInfo : NSObject
12 |
13 | @property (nonatomic, copy, readonly) NSString *method;
14 | @property (nonatomic, readonly) NSInteger level;
15 | @property (nonatomic, copy, readonly) NSString *inputFile;
16 | @property (nonatomic, copy, readonly) NSString *outputFile;
17 |
18 | - (instancetype)init NS_UNAVAILABLE;
19 | + (instancetype)new NS_UNAVAILABLE;
20 |
21 | @end
22 |
23 | @interface NOZCLICompressMode : NSObject
24 | @end
25 |
--------------------------------------------------------------------------------
/noz/NOZCLIDecompressMode.h:
--------------------------------------------------------------------------------
1 | //
2 | // NOZCLIDecompressMode.h
3 | // ZipUtilities
4 | //
5 | // Created by Nolan O'Brien on 5/7/17.
6 | // Copyright © 2017 NSProgrammer. All rights reserved.
7 | //
8 |
9 | #import "NOZCLIModeProtocol.h"
10 |
11 | @interface NOZCLIDecompressModeInfo : NSObject
12 |
13 | @property (nonatomic, copy, readonly) NSString *method;
14 | @property (nonatomic, copy, readonly) NSString *inputFile;
15 | @property (nonatomic, copy, readonly) NSString *outputFile;
16 |
17 | - (instancetype)init NS_UNAVAILABLE;
18 | + (instancetype)new NS_UNAVAILABLE;
19 |
20 | @end
21 |
22 | @interface NOZCLIDecompressMode : NSObject
23 | @end
24 |
--------------------------------------------------------------------------------
/noz/NOZCLIDumpMode.h:
--------------------------------------------------------------------------------
1 | //
2 | // NOZCLIDumpMode.h
3 | // ZipUtilities
4 | //
5 | // Created by Nolan O'Brien on 5/7/17.
6 | // Copyright © 2017 NSProgrammer. All rights reserved.
7 | //
8 |
9 | #import "NOZCLIModeProtocol.h"
10 |
11 | @interface NOZCLIDumpModeInfo : NSObject
12 |
13 | @property (nonatomic, readonly) BOOL list;
14 | @property (nonatomic, readonly) BOOL silenceArchiveInfo;
15 | @property (nonatomic, readonly) BOOL verbose;
16 | @property (nonatomic, copy, readonly) NSString *filePath;
17 |
18 | - (instancetype)init NS_UNAVAILABLE;
19 | + (instancetype)new NS_UNAVAILABLE;
20 |
21 | @end
22 |
23 | @interface NOZCLIDumpMode : NSObject
24 | @end
25 |
--------------------------------------------------------------------------------
/noz/NOZCLIMethodMode.h:
--------------------------------------------------------------------------------
1 | //
2 | // NOZCLIMethodMode.h
3 | // ZipUtilities
4 | //
5 | // Created by Nolan O'Brien on 5/8/17.
6 | // Copyright © 2017 NSProgrammer. All rights reserved.
7 | //
8 |
9 | #import "NOZCLIModeProtocol.h"
10 |
11 | @interface NOZCLIMethodModeInfo : NSObject
12 | - (instancetype)init NS_UNAVAILABLE;
13 | + (instancetype)new NS_UNAVAILABLE;
14 | @end
15 |
16 | @interface NOZCLIMethodMode : NSObject
17 | @end
18 |
--------------------------------------------------------------------------------
/noz/NOZCLIMethodMode.m:
--------------------------------------------------------------------------------
1 | //
2 | // NOZCLIMethodMode.m
3 | // ZipUtilities
4 | //
5 | // Created by Nolan O'Brien on 5/8/17.
6 | // Copyright © 2017 NSProgrammer. All rights reserved.
7 | //
8 |
9 | #import "NOZCLI.h"
10 | #import "NOZCLIMethodMode.h"
11 |
12 | @implementation NOZCLIMethodModeInfo
13 |
14 | - (instancetype)initInternal
15 | {
16 | return [super init];
17 | }
18 |
19 | @end
20 |
21 | @implementation NOZCLIMethodMode
22 |
23 | + (NSString *)modeFlag
24 | {
25 | return @"-A";
26 | }
27 |
28 | + (NSString *)modeName
29 | {
30 | return @"All Methods";
31 | }
32 |
33 | + (NSString *)modeExecutionDescription
34 | {
35 | return @"";
36 | }
37 |
38 | + (NSUInteger)modeExtraArgumentsSectionCount
39 | {
40 | return 0;
41 | }
42 |
43 | + (NSString *)modeExtraArgumentsSectionName:(NSUInteger)sectionIndex
44 | {
45 | return nil;
46 | }
47 |
48 | + (NSArray *)modeExtraArgumentsSectionDescriptions:(NSUInteger)sectionIndex
49 | {
50 | return nil;
51 | }
52 |
53 | + (id)infoFromArgs:(NSArray *)args
54 | environmentPath:(NSString *)envPath
55 | {
56 | return [[NOZCLIMethodModeInfo alloc] initInternal];
57 | }
58 |
59 | + (int)run:(NOZCLIMethodModeInfo *)unused
60 | {
61 | for (MethodInfo *info in NOZCLI_allMethods()) {
62 | printf("(%u) \"%s\":\n", (unsigned int)info.method, info.name.UTF8String);
63 | if (info.levels > 0) {
64 | printf("\tLevels: 1-%tu, Default Level: %tu\n", info.levels, info.defaultLevel);
65 | }
66 | printf("\tSupport: ");
67 | if (info.method == NOZCompressionMethodNone) {
68 | printf("Default");
69 | } else if (!info.encoder || !info.decoder) {
70 | printf("Unsupported");
71 | } else if (info.isDefaultCodec) {
72 | printf("Default");
73 | } else {
74 | printf("Extended");
75 | }
76 | printf("\n");
77 | }
78 | return 0;
79 | }
80 |
81 | @end
82 |
--------------------------------------------------------------------------------
/noz/NOZCLIModeProtocol.h:
--------------------------------------------------------------------------------
1 | //
2 | // NOZCLIModeProtocol.h
3 | // ZipUtilities
4 | //
5 | // Created by Nolan O'Brien on 5/8/17.
6 | // Copyright © 2017 NSProgrammer. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @protocol NOZCLIModeInfoProtocol
12 | @end
13 |
14 | @protocol NOZCLIModeProtocol
15 |
16 | + (NSString *)modeFlag;
17 | + (NSString *)modeName;
18 | + (NSString *)modeExecutionDescription;
19 |
20 | + (NSUInteger)modeExtraArgumentsSectionCount;
21 | + (NSString *)modeExtraArgumentsSectionName:(NSUInteger)sectionIndex;
22 | + (NSArray *)modeExtraArgumentsSectionDescriptions:(NSUInteger)sectionIndex;
23 |
24 | + (id)infoFromArgs:(NSArray *)args
25 | environmentPath:(NSString *)envPath;
26 | + (int)run:(id)info;
27 |
28 | @end
29 |
--------------------------------------------------------------------------------
/noz/NOZCLIUnzipMode.h:
--------------------------------------------------------------------------------
1 | //
2 | // NOZCLIUnzipMode.h
3 | // ZipUtilities
4 | //
5 | // Created by Nolan O'Brien on 5/7/17.
6 | // Copyright © 2017 NSProgrammer. All rights reserved.
7 | //
8 |
9 | #import "NOZCLIModeProtocol.h"
10 |
11 | @interface NOZCLIUnzipModeInfo : NSObject
12 | - (instancetype)init NS_UNAVAILABLE;
13 | + (instancetype)new NS_UNAVAILABLE;
14 | @end
15 |
16 | @interface NOZCLIUnzipMode : NSObject
17 | @end
18 |
--------------------------------------------------------------------------------
/noz/NOZCLIZipMode.h:
--------------------------------------------------------------------------------
1 | //
2 | // NOZCLIZipMode.h
3 | // ZipUtilities
4 | //
5 | // Created by Nolan O'Brien on 5/7/17.
6 | // Copyright © 2017 NSProgrammer. All rights reserved.
7 | //
8 |
9 | #import "NOZCLIModeProtocol.h"
10 |
11 | @interface NOZCLIZipModeInfo : NSObject
12 | - (instancetype)init NS_UNAVAILABLE;
13 | + (instancetype)new NS_UNAVAILABLE;
14 | @end
15 |
16 | @interface NOZCLIZipMode : NSObject
17 | @end
18 |
--------------------------------------------------------------------------------
/noz/main.m:
--------------------------------------------------------------------------------
1 | //
2 | // main.m
3 | // noz
4 | //
5 | // Created by Nolan O'Brien on 5/6/17.
6 | // Copyright © 2017 NSProgrammer. All rights reserved.
7 | //
8 |
9 | #import "NOZCLI.h"
10 |
11 | static NSArray *parseArgs(int argc, const char * argv[]);
12 |
13 | int main(int argc, const char * argv[])
14 | {
15 | int retVal = -1;
16 | @autoreleasepool {
17 | NSString *exe = nil;
18 | NSArray *args = parseArgs(argc, argv);
19 | if (args.count > 0) {
20 | NSString *path = args[0];
21 | exe = [path lastPathComponent];
22 | path = [path stringByDeletingLastPathComponent];
23 | args = [args subarrayWithRange:NSMakeRange(1, args.count - 1)];
24 |
25 | const char *pwd = getenv("PWD");
26 | NSString *currentDir = pwd ? @(pwd) : nil;
27 |
28 | retVal = NOZCLI_main(exe, path, currentDir, args);
29 | }
30 |
31 | if (retVal != 0) {
32 | if (retVal != -1) {
33 | printf("\n\n----------------------------------------\n\n");
34 | }
35 | NOZCLI_printUsage(exe, args.firstObject);
36 | }
37 | }
38 |
39 | return retVal;
40 | }
41 |
42 | static NSArray *parseArgs(int argc, const char * argv[])
43 | {
44 | NSMutableArray *args = [[NSMutableArray alloc] init];
45 | for (int c = 0; c < argc; c++) {
46 | [args addObject:@(argv[c])];
47 | }
48 | return [args copy];
49 | }
50 |
--------------------------------------------------------------------------------