extzstd 0.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (134) hide show
  1. checksums.yaml +5 -5
  2. data/HISTORY.ja.md +39 -0
  3. data/README.md +38 -56
  4. data/contrib/zstd/CHANGELOG +613 -0
  5. data/contrib/zstd/CODE_OF_CONDUCT.md +5 -0
  6. data/contrib/zstd/CONTRIBUTING.md +406 -0
  7. data/contrib/zstd/COPYING +339 -0
  8. data/contrib/zstd/Makefile +420 -0
  9. data/contrib/zstd/README.md +179 -41
  10. data/contrib/zstd/TESTING.md +44 -0
  11. data/contrib/zstd/appveyor.yml +292 -0
  12. data/contrib/zstd/lib/BUCK +234 -0
  13. data/contrib/zstd/lib/Makefile +451 -0
  14. data/contrib/zstd/lib/README.md +207 -0
  15. data/contrib/zstd/{common → lib/common}/bitstream.h +187 -138
  16. data/contrib/zstd/lib/common/compiler.h +288 -0
  17. data/contrib/zstd/lib/common/cpu.h +213 -0
  18. data/contrib/zstd/lib/common/debug.c +24 -0
  19. data/contrib/zstd/lib/common/debug.h +107 -0
  20. data/contrib/zstd/lib/common/entropy_common.c +362 -0
  21. data/contrib/zstd/{common → lib/common}/error_private.c +25 -12
  22. data/contrib/zstd/{common → lib/common}/error_private.h +14 -10
  23. data/contrib/zstd/{common → lib/common}/fse.h +173 -92
  24. data/contrib/zstd/{common → lib/common}/fse_decompress.c +149 -85
  25. data/contrib/zstd/lib/common/huf.h +361 -0
  26. data/contrib/zstd/{common → lib/common}/mem.h +115 -59
  27. data/contrib/zstd/lib/common/pool.c +350 -0
  28. data/contrib/zstd/lib/common/pool.h +84 -0
  29. data/contrib/zstd/lib/common/threading.c +122 -0
  30. data/contrib/zstd/lib/common/threading.h +155 -0
  31. data/contrib/zstd/{common → lib/common}/xxhash.c +55 -96
  32. data/contrib/zstd/{common → lib/common}/xxhash.h +23 -47
  33. data/contrib/zstd/lib/common/zstd_common.c +83 -0
  34. data/contrib/zstd/lib/common/zstd_deps.h +111 -0
  35. data/contrib/zstd/lib/common/zstd_errors.h +95 -0
  36. data/contrib/zstd/lib/common/zstd_internal.h +478 -0
  37. data/contrib/zstd/{compress → lib/compress}/fse_compress.c +214 -319
  38. data/contrib/zstd/lib/compress/hist.c +181 -0
  39. data/contrib/zstd/lib/compress/hist.h +75 -0
  40. data/contrib/zstd/lib/compress/huf_compress.c +913 -0
  41. data/contrib/zstd/lib/compress/zstd_compress.c +5208 -0
  42. data/contrib/zstd/lib/compress/zstd_compress_internal.h +1203 -0
  43. data/contrib/zstd/lib/compress/zstd_compress_literals.c +158 -0
  44. data/contrib/zstd/lib/compress/zstd_compress_literals.h +29 -0
  45. data/contrib/zstd/lib/compress/zstd_compress_sequences.c +433 -0
  46. data/contrib/zstd/lib/compress/zstd_compress_sequences.h +54 -0
  47. data/contrib/zstd/lib/compress/zstd_compress_superblock.c +849 -0
  48. data/contrib/zstd/lib/compress/zstd_compress_superblock.h +32 -0
  49. data/contrib/zstd/lib/compress/zstd_cwksp.h +561 -0
  50. data/contrib/zstd/lib/compress/zstd_double_fast.c +521 -0
  51. data/contrib/zstd/lib/compress/zstd_double_fast.h +38 -0
  52. data/contrib/zstd/lib/compress/zstd_fast.c +496 -0
  53. data/contrib/zstd/lib/compress/zstd_fast.h +37 -0
  54. data/contrib/zstd/lib/compress/zstd_lazy.c +1412 -0
  55. data/contrib/zstd/lib/compress/zstd_lazy.h +87 -0
  56. data/contrib/zstd/lib/compress/zstd_ldm.c +660 -0
  57. data/contrib/zstd/lib/compress/zstd_ldm.h +116 -0
  58. data/contrib/zstd/lib/compress/zstd_opt.c +1345 -0
  59. data/contrib/zstd/lib/compress/zstd_opt.h +56 -0
  60. data/contrib/zstd/lib/compress/zstdmt_compress.c +1811 -0
  61. data/contrib/zstd/lib/compress/zstdmt_compress.h +110 -0
  62. data/contrib/zstd/lib/decompress/huf_decompress.c +1350 -0
  63. data/contrib/zstd/lib/decompress/zstd_ddict.c +244 -0
  64. data/contrib/zstd/lib/decompress/zstd_ddict.h +44 -0
  65. data/contrib/zstd/lib/decompress/zstd_decompress.c +1930 -0
  66. data/contrib/zstd/lib/decompress/zstd_decompress_block.c +1540 -0
  67. data/contrib/zstd/lib/decompress/zstd_decompress_block.h +62 -0
  68. data/contrib/zstd/lib/decompress/zstd_decompress_internal.h +190 -0
  69. data/contrib/zstd/{common → lib/deprecated}/zbuff.h +68 -45
  70. data/contrib/zstd/lib/deprecated/zbuff_common.c +26 -0
  71. data/contrib/zstd/lib/deprecated/zbuff_compress.c +147 -0
  72. data/contrib/zstd/lib/deprecated/zbuff_decompress.c +75 -0
  73. data/contrib/zstd/lib/dictBuilder/cover.c +1245 -0
  74. data/contrib/zstd/lib/dictBuilder/cover.h +157 -0
  75. data/contrib/zstd/{dictBuilder → lib/dictBuilder}/divsufsort.c +3 -3
  76. data/contrib/zstd/{dictBuilder → lib/dictBuilder}/divsufsort.h +0 -0
  77. data/contrib/zstd/lib/dictBuilder/fastcover.c +758 -0
  78. data/contrib/zstd/{dictBuilder → lib/dictBuilder}/zdict.c +318 -194
  79. data/contrib/zstd/lib/dictBuilder/zdict.h +305 -0
  80. data/contrib/zstd/{legacy → lib/legacy}/zstd_legacy.h +171 -15
  81. data/contrib/zstd/{legacy → lib/legacy}/zstd_v01.c +191 -124
  82. data/contrib/zstd/{legacy → lib/legacy}/zstd_v01.h +19 -5
  83. data/contrib/zstd/{legacy → lib/legacy}/zstd_v02.c +125 -125
  84. data/contrib/zstd/{legacy → lib/legacy}/zstd_v02.h +19 -5
  85. data/contrib/zstd/{legacy → lib/legacy}/zstd_v03.c +125 -124
  86. data/contrib/zstd/{legacy → lib/legacy}/zstd_v03.h +20 -6
  87. data/contrib/zstd/{legacy → lib/legacy}/zstd_v04.c +151 -299
  88. data/contrib/zstd/{legacy → lib/legacy}/zstd_v04.h +19 -5
  89. data/contrib/zstd/{legacy → lib/legacy}/zstd_v05.c +237 -243
  90. data/contrib/zstd/{legacy → lib/legacy}/zstd_v05.h +19 -6
  91. data/contrib/zstd/{legacy → lib/legacy}/zstd_v06.c +130 -143
  92. data/contrib/zstd/{legacy → lib/legacy}/zstd_v06.h +18 -5
  93. data/contrib/zstd/{legacy → lib/legacy}/zstd_v07.c +158 -157
  94. data/contrib/zstd/{legacy → lib/legacy}/zstd_v07.h +19 -5
  95. data/contrib/zstd/lib/libzstd.pc.in +15 -0
  96. data/contrib/zstd/lib/zstd.h +2391 -0
  97. data/ext/depend +2 -0
  98. data/ext/extconf.rb +15 -6
  99. data/ext/extzstd.c +76 -145
  100. data/ext/extzstd.h +80 -31
  101. data/ext/extzstd_stream.c +417 -142
  102. data/ext/libzstd_conf.h +8 -0
  103. data/ext/zstd_common.c +10 -7
  104. data/ext/zstd_compress.c +14 -5
  105. data/ext/zstd_decompress.c +5 -4
  106. data/ext/zstd_dictbuilder.c +9 -4
  107. data/ext/zstd_dictbuilder_fastcover.c +3 -0
  108. data/ext/zstd_legacy_v01.c +3 -1
  109. data/ext/zstd_legacy_v02.c +3 -1
  110. data/ext/zstd_legacy_v03.c +3 -1
  111. data/ext/zstd_legacy_v04.c +3 -1
  112. data/ext/zstd_legacy_v05.c +3 -1
  113. data/ext/zstd_legacy_v06.c +3 -1
  114. data/ext/zstd_legacy_v07.c +3 -1
  115. data/gemstub.rb +10 -24
  116. data/lib/extzstd.rb +64 -179
  117. data/lib/extzstd/version.rb +6 -1
  118. data/test/test_basic.rb +9 -6
  119. metadata +113 -57
  120. data/HISTORY.ja +0 -5
  121. data/contrib/zstd/common/entropy_common.c +0 -225
  122. data/contrib/zstd/common/huf.h +0 -228
  123. data/contrib/zstd/common/zstd_common.c +0 -83
  124. data/contrib/zstd/common/zstd_errors.h +0 -60
  125. data/contrib/zstd/common/zstd_internal.h +0 -267
  126. data/contrib/zstd/compress/huf_compress.c +0 -533
  127. data/contrib/zstd/compress/zbuff_compress.c +0 -319
  128. data/contrib/zstd/compress/zstd_compress.c +0 -3264
  129. data/contrib/zstd/compress/zstd_opt.h +0 -900
  130. data/contrib/zstd/decompress/huf_decompress.c +0 -883
  131. data/contrib/zstd/decompress/zbuff_decompress.c +0 -252
  132. data/contrib/zstd/decompress/zstd_decompress.c +0 -1842
  133. data/contrib/zstd/dictBuilder/zdict.h +0 -111
  134. data/contrib/zstd/zstd.h +0 -640
@@ -0,0 +1,420 @@
1
+ # ################################################################
2
+ # Copyright (c) 2015-2020, 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
+ # verbose mode (print commands) on V=1 or VERBOSE=1
12
+ Q = $(if $(filter 1,$(V) $(VERBOSE)),,@)
13
+
14
+ PRGDIR = programs
15
+ ZSTDDIR = lib
16
+ BUILDIR = build
17
+ ZWRAPDIR = zlibWrapper
18
+ TESTDIR = tests
19
+ FUZZDIR = $(TESTDIR)/fuzz
20
+
21
+ # Define nul output
22
+ VOID = /dev/null
23
+
24
+ # When cross-compiling from linux to windows, you might
25
+ # need to specify this as "Windows." Fedora build fails
26
+ # without it.
27
+ #
28
+ # Note: mingw-w64 build from linux to windows does not
29
+ # fail on other tested distros (ubuntu, debian) even
30
+ # without manually specifying the TARGET_SYSTEM.
31
+ TARGET_SYSTEM ?= $(OS)
32
+
33
+ ifneq (,$(filter Windows%,$(TARGET_SYSTEM)))
34
+ EXT =.exe
35
+ else
36
+ EXT =
37
+ endif
38
+
39
+ ## default: Build lib-release and zstd-release
40
+ .PHONY: default
41
+ default: lib-release zstd-release
42
+
43
+ .PHONY: all
44
+ all: allmost examples manual contrib
45
+
46
+ .PHONY: allmost
47
+ allmost: allzstd zlibwrapper
48
+
49
+ # skip zwrapper, can't build that on alternate architectures without the proper zlib installed
50
+ .PHONY: allzstd
51
+ allzstd: lib-all
52
+ $(Q)$(MAKE) -C $(PRGDIR) all
53
+ $(Q)$(MAKE) -C $(TESTDIR) all
54
+
55
+ .PHONY: all32
56
+ all32:
57
+ $(MAKE) -C $(PRGDIR) zstd32
58
+ $(MAKE) -C $(TESTDIR) all32
59
+
60
+ .PHONY: lib lib-release libzstd.a
61
+ lib-all : lib
62
+ lib lib-release lib-all :
63
+ $(Q)$(MAKE) -C $(ZSTDDIR) $@
64
+
65
+ .PHONY: zstd zstd-release
66
+ zstd zstd-release:
67
+ $(Q)$(MAKE) -C $(PRGDIR) $@
68
+ $(Q)ln -sf $(PRGDIR)/zstd$(EXT) zstd$(EXT)
69
+
70
+ .PHONY: zstdmt
71
+ zstdmt:
72
+ $(Q)$(MAKE) -C $(PRGDIR) $@
73
+ $(Q)cp $(PRGDIR)/zstd$(EXT) ./zstdmt$(EXT)
74
+
75
+ .PHONY: zlibwrapper
76
+ zlibwrapper: lib
77
+ $(MAKE) -C $(ZWRAPDIR) all
78
+
79
+ ## test: run long-duration tests
80
+ .PHONY: test
81
+ DEBUGLEVEL ?= 1
82
+ test: MOREFLAGS += -g -Werror
83
+ test:
84
+ DEBUGLEVEL=$(DEBUGLEVEL) MOREFLAGS="$(MOREFLAGS)" $(MAKE) -j -C $(PRGDIR) allVariants
85
+ $(MAKE) -C $(TESTDIR) $@
86
+ ZSTD=../../programs/zstd $(MAKE) -C doc/educational_decoder $@
87
+
88
+ ## shortest: same as `make check`
89
+ .PHONY: shortest
90
+ shortest:
91
+ $(Q)$(MAKE) -C $(TESTDIR) $@
92
+
93
+ ## check: run basic tests for `zstd` cli
94
+ .PHONY: check
95
+ check: shortest
96
+
97
+ .PHONY: automated_benchmarking
98
+ automated_benchmarking:
99
+ $(MAKE) -C $(TESTDIR) $@
100
+
101
+ .PHONY: benchmarking
102
+ benchmarking: automated_benchmarking
103
+
104
+ ## examples: build all examples in `examples/` directory
105
+ .PHONY: examples
106
+ examples: lib
107
+ $(MAKE) -C examples all
108
+
109
+ ## manual: generate API documentation in html format
110
+ .PHONY: manual
111
+ manual:
112
+ $(MAKE) -C contrib/gen_html $@
113
+
114
+ ## man: generate man page
115
+ .PHONY: man
116
+ man:
117
+ $(MAKE) -C programs $@
118
+
119
+ ## contrib: build all supported projects in `/contrib` directory
120
+ .PHONY: contrib
121
+ contrib: lib
122
+ $(MAKE) -C contrib/pzstd all
123
+ $(MAKE) -C contrib/seekable_format/examples all
124
+ $(MAKE) -C contrib/seekable_format/tests test
125
+ $(MAKE) -C contrib/largeNbDicts all
126
+ cd contrib/single_file_libs/ ; ./build_decoder_test.sh
127
+ cd contrib/single_file_libs/ ; ./build_library_test.sh
128
+
129
+ .PHONY: cleanTabs
130
+ cleanTabs:
131
+ cd contrib; ./cleanTabs
132
+
133
+ .PHONY: clean
134
+ clean:
135
+ $(Q)$(MAKE) -C $(ZSTDDIR) $@ > $(VOID)
136
+ $(Q)$(MAKE) -C $(PRGDIR) $@ > $(VOID)
137
+ $(Q)$(MAKE) -C $(TESTDIR) $@ > $(VOID)
138
+ $(Q)$(MAKE) -C $(ZWRAPDIR) $@ > $(VOID)
139
+ $(Q)$(MAKE) -C examples/ $@ > $(VOID)
140
+ $(Q)$(MAKE) -C contrib/gen_html $@ > $(VOID)
141
+ $(Q)$(MAKE) -C contrib/pzstd $@ > $(VOID)
142
+ $(Q)$(MAKE) -C contrib/seekable_format/examples $@ > $(VOID)
143
+ $(Q)$(MAKE) -C contrib/seekable_format/tests $@ > $(VOID)
144
+ $(Q)$(MAKE) -C contrib/largeNbDicts $@ > $(VOID)
145
+ $(Q)$(RM) zstd$(EXT) zstdmt$(EXT) tmp*
146
+ $(Q)$(RM) -r lz4
147
+ @echo Cleaning completed
148
+
149
+ #------------------------------------------------------------------------------
150
+ # make install is validated only for Linux, macOS, Hurd and some BSD targets
151
+ #------------------------------------------------------------------------------
152
+ ifneq (,$(filter $(shell uname),Linux Darwin GNU/kFreeBSD GNU OpenBSD FreeBSD DragonFly NetBSD MSYS_NT Haiku))
153
+
154
+ HOST_OS = POSIX
155
+ CMAKE_PARAMS = -DZSTD_BUILD_CONTRIB:BOOL=ON -DZSTD_BUILD_STATIC:BOOL=ON -DZSTD_BUILD_TESTS:BOOL=ON -DZSTD_ZLIB_SUPPORT:BOOL=ON -DZSTD_LZMA_SUPPORT:BOOL=ON -DCMAKE_BUILD_TYPE=Release
156
+
157
+ HAVE_COLORNEVER = $(shell echo a | egrep --color=never a > /dev/null 2> /dev/null && echo 1 || echo 0)
158
+ EGREP_OPTIONS ?=
159
+ ifeq ($HAVE_COLORNEVER, 1)
160
+ EGREP_OPTIONS += --color=never
161
+ endif
162
+ EGREP = egrep $(EGREP_OPTIONS)
163
+
164
+ # Print a two column output of targets and their description. To add a target description, put a
165
+ # comment in the Makefile with the format "## <TARGET>: <DESCRIPTION>". For example:
166
+ #
167
+ ## list: Print all targets and their descriptions (if provided)
168
+ .PHONY: list
169
+ list:
170
+ $(Q)TARGETS=$$($(MAKE) -pRrq -f $(lastword $(MAKEFILE_LIST)) : 2>/dev/null \
171
+ | awk -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' \
172
+ | $(EGREP) -v -e '^[^[:alnum:]]' | sort); \
173
+ { \
174
+ printf "Target Name\tDescription\n"; \
175
+ printf "%0.s-" {1..16}; printf "\t"; printf "%0.s-" {1..40}; printf "\n"; \
176
+ for target in $$TARGETS; do \
177
+ line=$$($(EGREP) "^##[[:space:]]+$$target:" $(lastword $(MAKEFILE_LIST))); \
178
+ description=$$(echo $$line | awk '{i=index($$0,":"); print substr($$0,i+1)}' | xargs); \
179
+ printf "$$target\t$$description\n"; \
180
+ done \
181
+ } | column -t -s $$'\t'
182
+
183
+ .PHONY: install armtest usan asan uasan
184
+ install:
185
+ $(Q)$(MAKE) -C $(ZSTDDIR) $@
186
+ $(Q)$(MAKE) -C $(PRGDIR) $@
187
+
188
+ .PHONY: uninstall
189
+ uninstall:
190
+ $(Q)$(MAKE) -C $(ZSTDDIR) $@
191
+ $(Q)$(MAKE) -C $(PRGDIR) $@
192
+
193
+ .PHONY: travis-install
194
+ travis-install:
195
+ $(MAKE) install PREFIX=~/install_test_dir
196
+
197
+ .PHONY: gcc5build
198
+ gcc5build: clean
199
+ gcc-5 -v
200
+ CC=gcc-5 $(MAKE) all MOREFLAGS="-Werror"
201
+
202
+ .PHONY: gcc6build
203
+ gcc6build: clean
204
+ gcc-6 -v
205
+ CC=gcc-6 $(MAKE) all MOREFLAGS="-Werror"
206
+
207
+ .PHONY: gcc7build
208
+ gcc7build: clean
209
+ gcc-7 -v
210
+ CC=gcc-7 $(MAKE) all MOREFLAGS="-Werror"
211
+
212
+ .PHONY: clangbuild
213
+ clangbuild: clean
214
+ clang -v
215
+ CXX=clang++ CC=clang CFLAGS="-Werror -Wconversion -Wno-sign-conversion -Wdocumentation" $(MAKE) all
216
+
217
+ m32build: clean
218
+ gcc -v
219
+ $(MAKE) all32
220
+
221
+ armbuild: clean
222
+ CC=arm-linux-gnueabi-gcc CFLAGS="-Werror" $(MAKE) allzstd
223
+
224
+ aarch64build: clean
225
+ CC=aarch64-linux-gnu-gcc CFLAGS="-Werror" $(MAKE) allzstd
226
+
227
+ ppcbuild: clean
228
+ CC=powerpc-linux-gnu-gcc CFLAGS="-m32 -Wno-attributes -Werror" $(MAKE) allzstd
229
+
230
+ ppc64build: clean
231
+ CC=powerpc-linux-gnu-gcc CFLAGS="-m64 -Werror" $(MAKE) allzstd
232
+
233
+ armfuzz: clean
234
+ CC=arm-linux-gnueabi-gcc QEMU_SYS=qemu-arm-static MOREFLAGS="-static" FUZZER_FLAGS=--no-big-tests $(MAKE) -C $(TESTDIR) fuzztest
235
+
236
+ aarch64fuzz: clean
237
+ ld -v
238
+ CC=aarch64-linux-gnu-gcc QEMU_SYS=qemu-aarch64-static MOREFLAGS="-static" FUZZER_FLAGS=--no-big-tests $(MAKE) -C $(TESTDIR) fuzztest
239
+
240
+ ppcfuzz: clean
241
+ CC=powerpc-linux-gnu-gcc QEMU_SYS=qemu-ppc-static MOREFLAGS="-static" FUZZER_FLAGS=--no-big-tests $(MAKE) -C $(TESTDIR) fuzztest
242
+
243
+ ppc64fuzz: clean
244
+ CC=powerpc-linux-gnu-gcc QEMU_SYS=qemu-ppc64-static MOREFLAGS="-m64 -static" FUZZER_FLAGS=--no-big-tests $(MAKE) -C $(TESTDIR) fuzztest
245
+
246
+ .PHONY: cxxtest
247
+ cxxtest: CXXFLAGS += -Wall -Wextra -Wundef -Wshadow -Wcast-align -Werror
248
+ cxxtest: clean
249
+ $(MAKE) -C $(PRGDIR) all CC="$(CXX) -Wno-deprecated" CFLAGS="$(CXXFLAGS)" # adding -Wno-deprecated to avoid clang++ warning on dealing with C files directly
250
+
251
+ gcc5test: clean
252
+ gcc-5 -v
253
+ $(MAKE) all CC=gcc-5 MOREFLAGS="-Werror"
254
+
255
+ gcc6test: clean
256
+ gcc-6 -v
257
+ $(MAKE) all CC=gcc-6 MOREFLAGS="-Werror"
258
+
259
+ armtest: clean
260
+ $(MAKE) -C $(TESTDIR) datagen # use native, faster
261
+ $(MAKE) -C $(TESTDIR) test CC=arm-linux-gnueabi-gcc QEMU_SYS=qemu-arm-static ZSTDRTTEST= MOREFLAGS="-Werror -static" FUZZER_FLAGS=--no-big-tests
262
+
263
+ aarch64test:
264
+ $(MAKE) -C $(TESTDIR) datagen # use native, faster
265
+ $(MAKE) -C $(TESTDIR) test CC=aarch64-linux-gnu-gcc QEMU_SYS=qemu-aarch64-static ZSTDRTTEST= MOREFLAGS="-Werror -static" FUZZER_FLAGS=--no-big-tests
266
+
267
+ ppctest: clean
268
+ $(MAKE) -C $(TESTDIR) datagen # use native, faster
269
+ $(MAKE) -C $(TESTDIR) test CC=powerpc-linux-gnu-gcc QEMU_SYS=qemu-ppc-static ZSTDRTTEST= MOREFLAGS="-Werror -Wno-attributes -static" FUZZER_FLAGS=--no-big-tests
270
+
271
+ ppc64test: clean
272
+ $(MAKE) -C $(TESTDIR) datagen # use native, faster
273
+ $(MAKE) -C $(TESTDIR) test CC=powerpc-linux-gnu-gcc QEMU_SYS=qemu-ppc64-static ZSTDRTTEST= MOREFLAGS="-m64 -static" FUZZER_FLAGS=--no-big-tests
274
+
275
+ arm-ppc-compilation:
276
+ $(MAKE) -C $(PRGDIR) clean zstd CC=arm-linux-gnueabi-gcc QEMU_SYS=qemu-arm-static ZSTDRTTEST= MOREFLAGS="-Werror -static"
277
+ $(MAKE) -C $(PRGDIR) clean zstd CC=aarch64-linux-gnu-gcc QEMU_SYS=qemu-aarch64-static ZSTDRTTEST= MOREFLAGS="-Werror -static"
278
+ $(MAKE) -C $(PRGDIR) clean zstd CC=powerpc-linux-gnu-gcc QEMU_SYS=qemu-ppc-static ZSTDRTTEST= MOREFLAGS="-Werror -Wno-attributes -static"
279
+ $(MAKE) -C $(PRGDIR) clean zstd CC=powerpc-linux-gnu-gcc QEMU_SYS=qemu-ppc64-static ZSTDRTTEST= MOREFLAGS="-m64 -static"
280
+
281
+ regressiontest:
282
+ $(MAKE) -C $(FUZZDIR) regressiontest
283
+
284
+ uasanregressiontest:
285
+ $(MAKE) -C $(FUZZDIR) regressiontest CC=clang CXX=clang++ CFLAGS="-O3 -fsanitize=address,undefined" CXXFLAGS="-O3 -fsanitize=address,undefined"
286
+
287
+ msanregressiontest:
288
+ $(MAKE) -C $(FUZZDIR) regressiontest CC=clang CXX=clang++ CFLAGS="-O3 -fsanitize=memory" CXXFLAGS="-O3 -fsanitize=memory"
289
+
290
+ # run UBsan with -fsanitize-recover=signed-integer-overflow
291
+ # due to a bug in UBsan when doing pointer subtraction
292
+ # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63303
293
+
294
+ usan: clean
295
+ $(MAKE) test CC=clang MOREFLAGS="-g -fno-sanitize-recover=all -fsanitize-recover=signed-integer-overflow -fsanitize=undefined -Werror"
296
+
297
+ asan: clean
298
+ $(MAKE) test CC=clang MOREFLAGS="-g -fsanitize=address -Werror"
299
+
300
+ asan-%: clean
301
+ LDFLAGS=-fuse-ld=gold MOREFLAGS="-g -fno-sanitize-recover=all -fsanitize=address -Werror" $(MAKE) -C $(TESTDIR) $*
302
+
303
+ msan: clean
304
+ $(MAKE) test CC=clang MOREFLAGS="-g -fsanitize=memory -fno-omit-frame-pointer -Werror" HAVE_LZMA=0 # datagen.c fails this test for no obvious reason
305
+
306
+ msan-%: clean
307
+ LDFLAGS=-fuse-ld=gold MOREFLAGS="-g -fno-sanitize-recover=all -fsanitize=memory -fno-omit-frame-pointer -Werror" FUZZER_FLAGS=--no-big-tests $(MAKE) -C $(TESTDIR) HAVE_LZMA=0 $*
308
+
309
+ asan32: clean
310
+ $(MAKE) -C $(TESTDIR) test32 CC=clang MOREFLAGS="-g -fsanitize=address"
311
+
312
+ uasan: clean
313
+ $(MAKE) test CC=clang MOREFLAGS="-g -fno-sanitize-recover=all -fsanitize-recover=signed-integer-overflow -fsanitize=address,undefined -Werror"
314
+
315
+ uasan-%: clean
316
+ LDFLAGS=-fuse-ld=gold MOREFLAGS="-g -fno-sanitize-recover=all -fsanitize-recover=signed-integer-overflow -fsanitize=address,undefined -Werror" $(MAKE) -C $(TESTDIR) $*
317
+
318
+ tsan-%: clean
319
+ LDFLAGS=-fuse-ld=gold MOREFLAGS="-g -fno-sanitize-recover=all -fsanitize=thread -Werror" $(MAKE) -C $(TESTDIR) $* FUZZER_FLAGS=--no-big-tests
320
+
321
+ apt-install:
322
+ sudo apt-get -yq --no-install-suggests --no-install-recommends --force-yes install $(APT_PACKAGES)
323
+
324
+ apt-add-repo:
325
+ sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
326
+ sudo apt-get update -y -qq
327
+
328
+ ppcinstall:
329
+ APT_PACKAGES="qemu-system-ppc qemu-user-static gcc-powerpc-linux-gnu" $(MAKE) apt-install
330
+
331
+ arminstall:
332
+ APT_PACKAGES="qemu-system-arm qemu-user-static gcc-arm-linux-gnueabi libc6-dev-armel-cross gcc-aarch64-linux-gnu libc6-dev-arm64-cross" $(MAKE) apt-install
333
+
334
+ valgrindinstall:
335
+ APT_PACKAGES="valgrind" $(MAKE) apt-install
336
+
337
+ libc6install:
338
+ APT_PACKAGES="libc6-dev-i386 gcc-multilib" $(MAKE) apt-install
339
+
340
+ gcc6install: apt-add-repo
341
+ APT_PACKAGES="libc6-dev-i386 gcc-multilib gcc-6 gcc-6-multilib" $(MAKE) apt-install
342
+
343
+ gcc7install: apt-add-repo
344
+ APT_PACKAGES="libc6-dev-i386 gcc-multilib gcc-7 gcc-7-multilib" $(MAKE) apt-install
345
+
346
+ gcc8install: apt-add-repo
347
+ APT_PACKAGES="libc6-dev-i386 gcc-multilib gcc-8 gcc-8-multilib" $(MAKE) apt-install
348
+
349
+ gpp6install: apt-add-repo
350
+ APT_PACKAGES="libc6-dev-i386 g++-multilib gcc-6 g++-6 g++-6-multilib" $(MAKE) apt-install
351
+
352
+ clang38install:
353
+ APT_PACKAGES="clang-3.8" $(MAKE) apt-install
354
+
355
+ # Ubuntu 14.04 ships a too-old lz4
356
+ lz4install:
357
+ [ -e lz4 ] || git clone https://github.com/lz4/lz4 && sudo $(MAKE) -C lz4 install
358
+
359
+ endif
360
+
361
+
362
+ ifneq (,$(filter MSYS%,$(shell uname)))
363
+ HOST_OS = MSYS
364
+ CMAKE_PARAMS = -G"MSYS Makefiles" -DCMAKE_BUILD_TYPE=Debug -DZSTD_MULTITHREAD_SUPPORT:BOOL=OFF -DZSTD_BUILD_STATIC:BOOL=ON -DZSTD_BUILD_TESTS:BOOL=ON
365
+ endif
366
+
367
+
368
+ #------------------------------------------------------------------------
369
+ # target specific tests
370
+ #------------------------------------------------------------------------
371
+ ifneq (,$(filter $(HOST_OS),MSYS POSIX))
372
+ cmakebuild:
373
+ cmake --version
374
+ $(RM) -r $(BUILDIR)/cmake/build
375
+ mkdir $(BUILDIR)/cmake/build
376
+ cd $(BUILDIR)/cmake/build; cmake -DCMAKE_INSTALL_PREFIX:PATH=~/install_test_dir $(CMAKE_PARAMS) ..
377
+ $(MAKE) -C $(BUILDIR)/cmake/build -j4;
378
+ $(MAKE) -C $(BUILDIR)/cmake/build install;
379
+ $(MAKE) -C $(BUILDIR)/cmake/build uninstall;
380
+ cd $(BUILDIR)/cmake/build; ctest -V -L Medium
381
+
382
+ c89build: clean
383
+ $(CC) -v
384
+ CFLAGS="-std=c89 -Werror" $(MAKE) allmost # will fail, due to missing support for `long long`
385
+
386
+ gnu90build: clean
387
+ $(CC) -v
388
+ CFLAGS="-std=gnu90 -Werror" $(MAKE) allmost
389
+
390
+ c99build: clean
391
+ $(CC) -v
392
+ CFLAGS="-std=c99 -Werror" $(MAKE) allmost
393
+
394
+ gnu99build: clean
395
+ $(CC) -v
396
+ CFLAGS="-std=gnu99 -Werror" $(MAKE) allmost
397
+
398
+ c11build: clean
399
+ $(CC) -v
400
+ CFLAGS="-std=c11 -Werror" $(MAKE) allmost
401
+
402
+ bmix64build: clean
403
+ $(CC) -v
404
+ CFLAGS="-O3 -mbmi -Werror" $(MAKE) -C $(TESTDIR) test
405
+
406
+ bmix32build: clean
407
+ $(CC) -v
408
+ CFLAGS="-O3 -mbmi -mx32 -Werror" $(MAKE) -C $(TESTDIR) test
409
+
410
+ bmi32build: clean
411
+ $(CC) -v
412
+ CFLAGS="-O3 -mbmi -m32 -Werror" $(MAKE) -C $(TESTDIR) test
413
+
414
+ # static analyzer test uses clang's scan-build
415
+ # does not analyze zlibWrapper, due to detected issues in zlib source code
416
+ staticAnalyze: SCANBUILD ?= scan-build
417
+ staticAnalyze:
418
+ $(CC) -v
419
+ CC=$(CC) CPPFLAGS=-g $(SCANBUILD) --status-bugs -v $(MAKE) allzstd examples contrib
420
+ endif
@@ -1,61 +1,199 @@
1
- Zstandard library files
2
- ================================
1
+ <p align="center"><img src="https://raw.githubusercontent.com/facebook/zstd/dev/doc/images/zstd_logo86.png" alt="Zstandard"></p>
2
+
3
+ __Zstandard__, or `zstd` as short version, is a fast lossless compression algorithm,
4
+ targeting real-time compression scenarios at zlib-level and better compression ratios.
5
+ It's backed by a very fast entropy stage, provided by [Huff0 and FSE library](https://github.com/Cyan4973/FiniteStateEntropy).
6
+
7
+ The project is provided as an open-source dual [BSD](LICENSE) and [GPLv2](COPYING) licensed **C** library,
8
+ and a command line utility producing and decoding `.zst`, `.gz`, `.xz` and `.lz4` files.
9
+ Should your project require another programming language,
10
+ a list of known ports and bindings is provided on [Zstandard homepage](http://www.zstd.net/#other-languages).
3
11
 
4
- The __lib__ directory contains several directories.
5
- Depending on target use case, it's enough to include only files from relevant directories.
12
+ **Development branch status:**
6
13
 
14
+ [![Build Status][travisDevBadge]][travisLink]
15
+ [![Build status][AppveyorDevBadge]][AppveyorLink]
16
+ [![Build status][CircleDevBadge]][CircleLink]
17
+ [![Build status][CirrusDevBadge]][CirrusLink]
18
+ [![Fuzzing Status][OSSFuzzBadge]][OSSFuzzLink]
7
19
 
8
- #### API
20
+ [travisDevBadge]: https://travis-ci.org/facebook/zstd.svg?branch=dev "Continuous Integration test suite"
21
+ [travisLink]: https://travis-ci.org/facebook/zstd
22
+ [AppveyorDevBadge]: https://ci.appveyor.com/api/projects/status/xt38wbdxjk5mrbem/branch/dev?svg=true "Windows test suite"
23
+ [AppveyorLink]: https://ci.appveyor.com/project/YannCollet/zstd-p0yf0
24
+ [CircleDevBadge]: https://circleci.com/gh/facebook/zstd/tree/dev.svg?style=shield "Short test suite"
25
+ [CircleLink]: https://circleci.com/gh/facebook/zstd
26
+ [CirrusDevBadge]: https://api.cirrus-ci.com/github/facebook/zstd.svg?branch=dev
27
+ [CirrusLink]: https://cirrus-ci.com/github/facebook/zstd
28
+ [OSSFuzzBadge]: https://oss-fuzz-build-logs.storage.googleapis.com/badges/zstd.svg
29
+ [OSSFuzzLink]: https://bugs.chromium.org/p/oss-fuzz/issues/list?sort=-opened&can=1&q=proj:zstd
9
30
 
10
- Zstandard's stable API is exposed within [zstd.h](zstd.h),
11
- at the root of `lib` directory.
31
+ ## Benchmarks
12
32
 
33
+ For reference, several fast compression algorithms were tested and compared
34
+ on a server running Arch Linux (`Linux version 5.5.11-arch1-1`),
35
+ with a Core i9-9900K CPU @ 5.0GHz,
36
+ using [lzbench], an open-source in-memory benchmark by @inikep
37
+ compiled with [gcc] 9.3.0,
38
+ on the [Silesia compression corpus].
13
39
 
14
- #### Advanced API
40
+ [lzbench]: https://github.com/inikep/lzbench
41
+ [Silesia compression corpus]: http://sun.aei.polsl.pl/~sdeor/index.php?page=silesia
42
+ [gcc]: https://gcc.gnu.org/
15
43
 
16
- Some additional API may be useful if you're looking into advanced features :
17
- - common/error_public.h : transforms `size_t` function results into an `enum`,
18
- for precise error handling.
19
- - ZSTD_STATIC_LINKING_ONLY : if you define this macro _before_ including `zstd.h`,
20
- it will give access to advanced and experimental API.
21
- These APIs shall ___never be used with dynamic library___ !
22
- They are not "stable", their definition may change in the future.
23
- Only static linking is allowed.
44
+ | Compressor name | Ratio | Compression| Decompress.|
45
+ | --------------- | ------| -----------| ---------- |
46
+ | **zstd 1.4.5 -1** | 2.884 | 500 MB/s | 1660 MB/s |
47
+ | zlib 1.2.11 -1 | 2.743 | 90 MB/s | 400 MB/s |
48
+ | brotli 1.0.7 -0 | 2.703 | 400 MB/s | 450 MB/s |
49
+ | **zstd 1.4.5 --fast=1** | 2.434 | 570 MB/s | 2200 MB/s |
50
+ | **zstd 1.4.5 --fast=3** | 2.312 | 640 MB/s | 2300 MB/s |
51
+ | quicklz 1.5.0 -1 | 2.238 | 560 MB/s | 710 MB/s |
52
+ | **zstd 1.4.5 --fast=5** | 2.178 | 700 MB/s | 2420 MB/s |
53
+ | lzo1x 2.10 -1 | 2.106 | 690 MB/s | 820 MB/s |
54
+ | lz4 1.9.2 | 2.101 | 740 MB/s | 4530 MB/s |
55
+ | **zstd 1.4.5 --fast=7** | 2.096 | 750 MB/s | 2480 MB/s |
56
+ | lzf 3.6 -1 | 2.077 | 410 MB/s | 860 MB/s |
57
+ | snappy 1.1.8 | 2.073 | 560 MB/s | 1790 MB/s |
24
58
 
59
+ [zlib]: http://www.zlib.net/
60
+ [LZ4]: http://www.lz4.org/
25
61
 
26
- #### Modular build
62
+ The negative compression levels, specified with `--fast=#`,
63
+ offer faster compression and decompression speed in exchange for some loss in
64
+ compression ratio compared to level 1, as seen in the table above.
27
65
 
28
- Directory `common/` is required in all circumstances.
29
- You can select to support compression only, by just adding files from the `compress/` directory,
30
- In a similar way, you can build a decompressor-only library with the `decompress/` directory.
66
+ Zstd can also offer stronger compression ratios at the cost of compression speed.
67
+ Speed vs Compression trade-off is configurable by small increments.
68
+ Decompression speed is preserved and remains roughly the same at all settings,
69
+ a property shared by most LZ compression algorithms, such as [zlib] or lzma.
31
70
 
32
- Other optional functionalities provided are :
71
+ The following tests were run
72
+ on a server running Linux Debian (`Linux version 4.14.0-3-amd64`)
73
+ with a Core i7-6700K CPU @ 4.0GHz,
74
+ using [lzbench], an open-source in-memory benchmark by @inikep
75
+ compiled with [gcc] 7.3.0,
76
+ on the [Silesia compression corpus].
33
77
 
34
- - `dictBuilder/` : source files to create dictionaries.
35
- The API can be consulted in `dictBuilder/zdict.h`.
36
- This module also depends on `common/` and `compress/` .
78
+ Compression Speed vs Ratio | Decompression Speed
79
+ ---------------------------|--------------------
80
+ ![Compression Speed vs Ratio](doc/images/CSpeed2.png "Compression Speed vs Ratio") | ![Decompression Speed](doc/images/DSpeed3.png "Decompression Speed")
37
81
 
38
- - `legacy/` : source code to decompress previous versions of zstd, starting from `v0.1`.
39
- This module also depends on `common/` and `decompress/` .
40
- Library compilation must include directive `ZSTD_LEGACY_SUPPORT = 1` .
41
- The main API can be consulted in `legacy/zstd_legacy.h`.
42
- Advanced API from each version can be found in their relevant header file.
43
- For example, advanced API for version `v0.4` is in `legacy/zstd_v04.h` .
82
+ A few other algorithms can produce higher compression ratios at slower speeds, falling outside of the graph.
83
+ For a larger picture including slow modes, [click on this link](doc/images/DCspeed5.png).
44
84
 
45
85
 
46
- #### Obsolete streaming API
86
+ ## The case for Small Data compression
47
87
 
48
- Streaming is now provided within `zstd.h`.
49
- Older streaming API is still provided within `common/zbuff.h`.
50
- It is considered obsolete, and will be removed in a future version.
51
- Consider migrating towards newer streaming API.
88
+ Previous charts provide results applicable to typical file and stream scenarios (several MB). Small data comes with different perspectives.
52
89
 
90
+ The smaller the amount of data to compress, the more difficult it is to compress. This problem is common to all compression algorithms, and reason is, compression algorithms learn from past data how to compress future data. But at the beginning of a new data set, there is no "past" to build upon.
53
91
 
54
- #### Miscellaneous
92
+ To solve this situation, Zstd offers a __training mode__, which can be used to tune the algorithm for a selected type of data.
93
+ Training Zstandard is achieved by providing it with a few samples (one file per sample). The result of this training is stored in a file called "dictionary", which must be loaded before compression and decompression.
94
+ Using this dictionary, the compression ratio achievable on small data improves dramatically.
55
95
 
56
- The other files are not source code. There are :
96
+ The following example uses the `github-users` [sample set](https://github.com/facebook/zstd/releases/tag/v1.1.3), created from [github public API](https://developer.github.com/v3/users/#get-all-users).
97
+ It consists of roughly 10K records weighing about 1KB each.
57
98
 
58
- - LICENSE : contains the BSD license text
59
- - Makefile : script to compile or install zstd library (static and dynamic)
60
- - libzstd.pc.in : for pkg-config (`make install`)
61
- - README.md : this file
99
+ Compression Ratio | Compression Speed | Decompression Speed
100
+ ------------------|-------------------|--------------------
101
+ ![Compression Ratio](doc/images/dict-cr.png "Compression Ratio") | ![Compression Speed](doc/images/dict-cs.png "Compression Speed") | ![Decompression Speed](doc/images/dict-ds.png "Decompression Speed")
102
+
103
+
104
+ These compression gains are achieved while simultaneously providing _faster_ compression and decompression speeds.
105
+
106
+ Training works if there is some correlation in a family of small data samples. The more data-specific a dictionary is, the more efficient it is (there is no _universal dictionary_).
107
+ Hence, deploying one dictionary per type of data will provide the greatest benefits.
108
+ Dictionary gains are mostly effective in the first few KB. Then, the compression algorithm will gradually use previously decoded content to better compress the rest of the file.
109
+
110
+ ### Dictionary compression How To:
111
+
112
+ 1. Create the dictionary
113
+
114
+ `zstd --train FullPathToTrainingSet/* -o dictionaryName`
115
+
116
+ 2. Compress with dictionary
117
+
118
+ `zstd -D dictionaryName FILE`
119
+
120
+ 3. Decompress with dictionary
121
+
122
+ `zstd -D dictionaryName --decompress FILE.zst`
123
+
124
+
125
+ ## Build instructions
126
+
127
+ ### Makefile
128
+
129
+ If your system is compatible with standard `make` (or `gmake`),
130
+ invoking `make` in root directory will generate `zstd` cli in root directory.
131
+
132
+ Other available options include:
133
+ - `make install` : create and install zstd cli, library and man pages
134
+ - `make check` : create and run `zstd`, tests its behavior on local platform
135
+
136
+ ### cmake
137
+
138
+ A `cmake` project generator is provided within `build/cmake`.
139
+ It can generate Makefiles or other build scripts
140
+ to create `zstd` binary, and `libzstd` dynamic and static libraries.
141
+
142
+ By default, `CMAKE_BUILD_TYPE` is set to `Release`.
143
+
144
+ ### Meson
145
+
146
+ A Meson project is provided within [`build/meson`](build/meson). Follow
147
+ build instructions in that directory.
148
+
149
+ You can also take a look at [`.travis.yml`](.travis.yml) file for an
150
+ example about how Meson is used to build this project.
151
+
152
+ Note that default build type is **release**.
153
+
154
+ ### VCPKG
155
+ You can build and install zstd [vcpkg](https://github.com/Microsoft/vcpkg/) dependency manager:
156
+
157
+ git clone https://github.com/Microsoft/vcpkg.git
158
+ cd vcpkg
159
+ ./bootstrap-vcpkg.sh
160
+ ./vcpkg integrate install
161
+ ./vcpkg install zstd
162
+
163
+ The zstd port in vcpkg is kept up to date by Microsoft team members and community contributors.
164
+ If the version is out of date, please [create an issue or pull request](https://github.com/Microsoft/vcpkg) on the vcpkg repository.
165
+
166
+ ### Visual Studio (Windows)
167
+
168
+ Going into `build` directory, you will find additional possibilities:
169
+ - Projects for Visual Studio 2005, 2008 and 2010.
170
+ + VS2010 project is compatible with VS2012, VS2013, VS2015 and VS2017.
171
+ - Automated build scripts for Visual compiler by [@KrzysFR](https://github.com/KrzysFR), in `build/VS_scripts`,
172
+ which will build `zstd` cli and `libzstd` library without any need to open Visual Studio solution.
173
+
174
+ ### Buck
175
+
176
+ You can build the zstd binary via buck by executing: `buck build programs:zstd` from the root of the repo.
177
+ The output binary will be in `buck-out/gen/programs/`.
178
+
179
+ ## Testing
180
+
181
+ You can run quick local smoke tests by executing the `playTest.sh` script from the `src/tests` directory.
182
+ Two env variables `$ZSTD_BIN` and `$DATAGEN_BIN` are needed for the test script to locate the zstd and datagen binary.
183
+ For information on CI testing, please refer to TESTING.md
184
+
185
+ ## Status
186
+
187
+ Zstandard is currently deployed within Facebook. It is used continuously to compress large amounts of data in multiple formats and use cases.
188
+ Zstandard is considered safe for production environments.
189
+
190
+ ## License
191
+
192
+ Zstandard is dual-licensed under [BSD](LICENSE) and [GPLv2](COPYING).
193
+
194
+ ## Contributing
195
+
196
+ The "dev" branch is the one where all contributions are merged before reaching "master".
197
+ If you plan to propose a patch, please commit into the "dev" branch, or its own feature branch.
198
+ Direct commit to "master" are not permitted.
199
+ For more information, please read [CONTRIBUTING](CONTRIBUTING.md).