extzstd 0.1 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) hide show
  1. checksums.yaml +4 -4
  2. data/HISTORY.ja +5 -0
  3. data/README.md +5 -5
  4. data/contrib/zstd/CONTRIBUTING.md +42 -0
  5. data/contrib/zstd/LICENSE-examples +11 -0
  6. data/contrib/zstd/Makefile +315 -0
  7. data/contrib/zstd/NEWS +261 -0
  8. data/contrib/zstd/PATENTS +33 -0
  9. data/contrib/zstd/README.md +121 -41
  10. data/contrib/zstd/TESTING.md +44 -0
  11. data/contrib/zstd/appveyor.yml +178 -0
  12. data/contrib/zstd/circle.yml +75 -0
  13. data/contrib/zstd/lib/BUCK +186 -0
  14. data/contrib/zstd/lib/Makefile +163 -0
  15. data/contrib/zstd/lib/README.md +77 -0
  16. data/contrib/zstd/{common → lib/common}/bitstream.h +7 -4
  17. data/contrib/zstd/{common → lib/common}/entropy_common.c +19 -23
  18. data/contrib/zstd/{common → lib/common}/error_private.c +0 -0
  19. data/contrib/zstd/{common → lib/common}/error_private.h +0 -0
  20. data/contrib/zstd/{common → lib/common}/fse.h +94 -34
  21. data/contrib/zstd/{common → lib/common}/fse_decompress.c +18 -19
  22. data/contrib/zstd/{common → lib/common}/huf.h +52 -20
  23. data/contrib/zstd/{common → lib/common}/mem.h +17 -13
  24. data/contrib/zstd/lib/common/pool.c +194 -0
  25. data/contrib/zstd/lib/common/pool.h +56 -0
  26. data/contrib/zstd/lib/common/threading.c +80 -0
  27. data/contrib/zstd/lib/common/threading.h +104 -0
  28. data/contrib/zstd/{common → lib/common}/xxhash.c +3 -1
  29. data/contrib/zstd/{common → lib/common}/xxhash.h +11 -15
  30. data/contrib/zstd/{common → lib/common}/zstd_common.c +1 -11
  31. data/contrib/zstd/{common → lib/common}/zstd_errors.h +16 -2
  32. data/contrib/zstd/{common → lib/common}/zstd_internal.h +17 -1
  33. data/contrib/zstd/{compress → lib/compress}/fse_compress.c +138 -91
  34. data/contrib/zstd/{compress → lib/compress}/huf_compress.c +218 -67
  35. data/contrib/zstd/{compress → lib/compress}/zstd_compress.c +231 -108
  36. data/contrib/zstd/{compress → lib/compress}/zstd_opt.h +44 -25
  37. data/contrib/zstd/lib/compress/zstdmt_compress.c +739 -0
  38. data/contrib/zstd/lib/compress/zstdmt_compress.h +78 -0
  39. data/contrib/zstd/{decompress → lib/decompress}/huf_decompress.c +28 -23
  40. data/contrib/zstd/{decompress → lib/decompress}/zstd_decompress.c +814 -176
  41. data/contrib/zstd/{common → lib/deprecated}/zbuff.h +60 -39
  42. data/contrib/zstd/lib/deprecated/zbuff_common.c +26 -0
  43. data/contrib/zstd/lib/deprecated/zbuff_compress.c +145 -0
  44. data/contrib/zstd/lib/deprecated/zbuff_decompress.c +74 -0
  45. data/contrib/zstd/lib/dictBuilder/cover.c +1029 -0
  46. data/contrib/zstd/{dictBuilder → lib/dictBuilder}/divsufsort.c +0 -0
  47. data/contrib/zstd/{dictBuilder → lib/dictBuilder}/divsufsort.h +0 -0
  48. data/contrib/zstd/{dictBuilder → lib/dictBuilder}/zdict.c +68 -18
  49. data/contrib/zstd/lib/dictBuilder/zdict.h +201 -0
  50. data/contrib/zstd/{legacy → lib/legacy}/zstd_legacy.h +122 -7
  51. data/contrib/zstd/{legacy → lib/legacy}/zstd_v01.c +34 -3
  52. data/contrib/zstd/{legacy → lib/legacy}/zstd_v01.h +8 -0
  53. data/contrib/zstd/{legacy → lib/legacy}/zstd_v02.c +45 -12
  54. data/contrib/zstd/{legacy → lib/legacy}/zstd_v02.h +8 -0
  55. data/contrib/zstd/{legacy → lib/legacy}/zstd_v03.c +45 -12
  56. data/contrib/zstd/{legacy → lib/legacy}/zstd_v03.h +8 -0
  57. data/contrib/zstd/{legacy → lib/legacy}/zstd_v04.c +56 -33
  58. data/contrib/zstd/{legacy → lib/legacy}/zstd_v04.h +8 -0
  59. data/contrib/zstd/{legacy → lib/legacy}/zstd_v05.c +45 -18
  60. data/contrib/zstd/{legacy → lib/legacy}/zstd_v05.h +7 -0
  61. data/contrib/zstd/{legacy → lib/legacy}/zstd_v06.c +43 -16
  62. data/contrib/zstd/{legacy → lib/legacy}/zstd_v06.h +7 -0
  63. data/contrib/zstd/{legacy → lib/legacy}/zstd_v07.c +57 -23
  64. data/contrib/zstd/{legacy → lib/legacy}/zstd_v07.h +8 -0
  65. data/contrib/zstd/lib/libzstd.pc.in +14 -0
  66. data/contrib/zstd/{zstd.h → lib/zstd.h} +206 -71
  67. data/ext/depend +2 -0
  68. data/ext/extconf.rb +4 -4
  69. data/ext/extzstd.c +1 -1
  70. data/ext/zstd_common.c +5 -5
  71. data/ext/zstd_compress.c +3 -3
  72. data/ext/zstd_decompress.c +2 -2
  73. data/ext/zstd_dictbuilder.c +2 -2
  74. data/ext/zstd_legacy_v01.c +1 -1
  75. data/ext/zstd_legacy_v02.c +1 -1
  76. data/ext/zstd_legacy_v03.c +1 -1
  77. data/ext/zstd_legacy_v04.c +1 -1
  78. data/ext/zstd_legacy_v05.c +1 -1
  79. data/ext/zstd_legacy_v06.c +1 -1
  80. data/ext/zstd_legacy_v07.c +1 -1
  81. data/gemstub.rb +9 -5
  82. data/lib/extzstd/version.rb +1 -1
  83. metadata +73 -51
  84. data/contrib/zstd/compress/zbuff_compress.c +0 -319
  85. data/contrib/zstd/decompress/zbuff_decompress.c +0 -252
  86. data/contrib/zstd/dictBuilder/zdict.h +0 -111
@@ -1 +1 @@
1
- #include "../contrib/zstd/legacy/zstd_v05.c"
1
+ #include "../contrib/zstd/lib/legacy/zstd_v05.c"
@@ -1 +1 @@
1
- #include "../contrib/zstd/legacy/zstd_v06.c"
1
+ #include "../contrib/zstd/lib/legacy/zstd_v06.c"
@@ -1 +1 @@
1
- #include "../contrib/zstd/legacy/zstd_v07.c"
1
+ #include "../contrib/zstd/lib/legacy/zstd_v07.c"
data/gemstub.rb CHANGED
@@ -10,15 +10,15 @@ GEMSTUB = Gem::Specification.new do |s|
10
10
  s.version = version
11
11
  s.summary = "ruby bindings for Zstandard (zstd)"
12
12
  s.description = <<EOS
13
- unoficial ruby bindings for Zstandard (zstd) <https://github.com/Cyan4973/zstd>.
13
+ unoficial ruby bindings for Zstandard (zstd) <https://github.com/facebook/zstd>.
14
14
  EOS
15
- s.homepage = "https://osdn.jp/projects/rutsubo/"
16
- s.license = "2-clause BSD License"
15
+ s.homepage = "https://github.com/dearblue/ruby-extzstd/"
16
+ s.license = "BSD-2-Clause"
17
17
  s.author = "dearblue"
18
- s.email = "dearblue@users.osdn.me"
18
+ s.email = "dearblue@users.noreply.github.com"
19
19
 
20
20
  s.required_ruby_version = ">= 2.0"
21
- s.add_development_dependency "rake"
21
+ s.add_development_dependency "rake", ">= 12.0"
22
22
  end
23
23
 
24
24
  LIB << "lib/extzstd/version.rb"
@@ -35,3 +35,7 @@ end
35
35
  end
36
36
 
37
37
  EXTRA.concat(FileList["contrib/**/*"])
38
+
39
+ filter = %r(contrib/zstd/(?:build|contrib|doc|examples|lib/dll|programs|tests|zlibWrapper))
40
+ DOC.reject! { |path| path =~ filter }
41
+ EXTRA.reject! { |path| path =~ filter }
@@ -1,3 +1,3 @@
1
1
  module Zstd
2
- VERSION = "0.1"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: extzstd
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.1'
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - dearblue
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-11-02 00:00:00.000000000 Z
11
+ date: 2017-03-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -16,18 +16,18 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: '12.0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
27
- description: 'unoficial ruby bindings for Zstandard (zstd) <https://github.com/Cyan4973/zstd>.
26
+ version: '12.0'
27
+ description: 'unoficial ruby bindings for Zstandard (zstd) <https://github.com/facebook/zstd>.
28
28
 
29
29
  '
30
- email: dearblue@users.osdn.me
30
+ email: dearblue@users.noreply.github.com
31
31
  executables: []
32
32
  extensions:
33
33
  - ext/extconf.rb
@@ -37,6 +37,7 @@ extra_rdoc_files:
37
37
  - README.md
38
38
  - contrib/zstd/LICENSE
39
39
  - contrib/zstd/README.md
40
+ - contrib/zstd/lib/README.md
40
41
  - ext/extzstd.c
41
42
  - ext/extzstd.h
42
43
  - ext/extzstd_nogvls.h
@@ -59,50 +60,71 @@ files:
59
60
  - LICENSE
60
61
  - README.md
61
62
  - Rakefile
63
+ - contrib/zstd/CONTRIBUTING.md
62
64
  - contrib/zstd/LICENSE
65
+ - contrib/zstd/LICENSE-examples
66
+ - contrib/zstd/Makefile
67
+ - contrib/zstd/NEWS
68
+ - contrib/zstd/PATENTS
63
69
  - contrib/zstd/README.md
64
- - contrib/zstd/common/bitstream.h
65
- - contrib/zstd/common/entropy_common.c
66
- - contrib/zstd/common/error_private.c
67
- - contrib/zstd/common/error_private.h
68
- - contrib/zstd/common/fse.h
69
- - contrib/zstd/common/fse_decompress.c
70
- - contrib/zstd/common/huf.h
71
- - contrib/zstd/common/mem.h
72
- - contrib/zstd/common/xxhash.c
73
- - contrib/zstd/common/xxhash.h
74
- - contrib/zstd/common/zbuff.h
75
- - contrib/zstd/common/zstd_common.c
76
- - contrib/zstd/common/zstd_errors.h
77
- - contrib/zstd/common/zstd_internal.h
78
- - contrib/zstd/compress/fse_compress.c
79
- - contrib/zstd/compress/huf_compress.c
80
- - contrib/zstd/compress/zbuff_compress.c
81
- - contrib/zstd/compress/zstd_compress.c
82
- - contrib/zstd/compress/zstd_opt.h
83
- - contrib/zstd/decompress/huf_decompress.c
84
- - contrib/zstd/decompress/zbuff_decompress.c
85
- - contrib/zstd/decompress/zstd_decompress.c
86
- - contrib/zstd/dictBuilder/divsufsort.c
87
- - contrib/zstd/dictBuilder/divsufsort.h
88
- - contrib/zstd/dictBuilder/zdict.c
89
- - contrib/zstd/dictBuilder/zdict.h
90
- - contrib/zstd/legacy/zstd_legacy.h
91
- - contrib/zstd/legacy/zstd_v01.c
92
- - contrib/zstd/legacy/zstd_v01.h
93
- - contrib/zstd/legacy/zstd_v02.c
94
- - contrib/zstd/legacy/zstd_v02.h
95
- - contrib/zstd/legacy/zstd_v03.c
96
- - contrib/zstd/legacy/zstd_v03.h
97
- - contrib/zstd/legacy/zstd_v04.c
98
- - contrib/zstd/legacy/zstd_v04.h
99
- - contrib/zstd/legacy/zstd_v05.c
100
- - contrib/zstd/legacy/zstd_v05.h
101
- - contrib/zstd/legacy/zstd_v06.c
102
- - contrib/zstd/legacy/zstd_v06.h
103
- - contrib/zstd/legacy/zstd_v07.c
104
- - contrib/zstd/legacy/zstd_v07.h
105
- - contrib/zstd/zstd.h
70
+ - contrib/zstd/TESTING.md
71
+ - contrib/zstd/appveyor.yml
72
+ - contrib/zstd/circle.yml
73
+ - contrib/zstd/lib/BUCK
74
+ - contrib/zstd/lib/Makefile
75
+ - contrib/zstd/lib/README.md
76
+ - contrib/zstd/lib/common/bitstream.h
77
+ - contrib/zstd/lib/common/entropy_common.c
78
+ - contrib/zstd/lib/common/error_private.c
79
+ - contrib/zstd/lib/common/error_private.h
80
+ - contrib/zstd/lib/common/fse.h
81
+ - contrib/zstd/lib/common/fse_decompress.c
82
+ - contrib/zstd/lib/common/huf.h
83
+ - contrib/zstd/lib/common/mem.h
84
+ - contrib/zstd/lib/common/pool.c
85
+ - contrib/zstd/lib/common/pool.h
86
+ - contrib/zstd/lib/common/threading.c
87
+ - contrib/zstd/lib/common/threading.h
88
+ - contrib/zstd/lib/common/xxhash.c
89
+ - contrib/zstd/lib/common/xxhash.h
90
+ - contrib/zstd/lib/common/zstd_common.c
91
+ - contrib/zstd/lib/common/zstd_errors.h
92
+ - contrib/zstd/lib/common/zstd_internal.h
93
+ - contrib/zstd/lib/compress/fse_compress.c
94
+ - contrib/zstd/lib/compress/huf_compress.c
95
+ - contrib/zstd/lib/compress/zstd_compress.c
96
+ - contrib/zstd/lib/compress/zstd_opt.h
97
+ - contrib/zstd/lib/compress/zstdmt_compress.c
98
+ - contrib/zstd/lib/compress/zstdmt_compress.h
99
+ - contrib/zstd/lib/decompress/huf_decompress.c
100
+ - contrib/zstd/lib/decompress/zstd_decompress.c
101
+ - contrib/zstd/lib/deprecated/zbuff.h
102
+ - contrib/zstd/lib/deprecated/zbuff_common.c
103
+ - contrib/zstd/lib/deprecated/zbuff_compress.c
104
+ - contrib/zstd/lib/deprecated/zbuff_decompress.c
105
+ - contrib/zstd/lib/dictBuilder/cover.c
106
+ - contrib/zstd/lib/dictBuilder/divsufsort.c
107
+ - contrib/zstd/lib/dictBuilder/divsufsort.h
108
+ - contrib/zstd/lib/dictBuilder/zdict.c
109
+ - contrib/zstd/lib/dictBuilder/zdict.h
110
+ - contrib/zstd/lib/legacy/zstd_legacy.h
111
+ - contrib/zstd/lib/legacy/zstd_v01.c
112
+ - contrib/zstd/lib/legacy/zstd_v01.h
113
+ - contrib/zstd/lib/legacy/zstd_v02.c
114
+ - contrib/zstd/lib/legacy/zstd_v02.h
115
+ - contrib/zstd/lib/legacy/zstd_v03.c
116
+ - contrib/zstd/lib/legacy/zstd_v03.h
117
+ - contrib/zstd/lib/legacy/zstd_v04.c
118
+ - contrib/zstd/lib/legacy/zstd_v04.h
119
+ - contrib/zstd/lib/legacy/zstd_v05.c
120
+ - contrib/zstd/lib/legacy/zstd_v05.h
121
+ - contrib/zstd/lib/legacy/zstd_v06.c
122
+ - contrib/zstd/lib/legacy/zstd_v06.h
123
+ - contrib/zstd/lib/legacy/zstd_v07.c
124
+ - contrib/zstd/lib/legacy/zstd_v07.h
125
+ - contrib/zstd/lib/libzstd.pc.in
126
+ - contrib/zstd/lib/zstd.h
127
+ - ext/depend
106
128
  - ext/extconf.rb
107
129
  - ext/extzstd.c
108
130
  - ext/extzstd.h
@@ -123,9 +145,9 @@ files:
123
145
  - lib/extzstd.rb
124
146
  - lib/extzstd/version.rb
125
147
  - test/test_basic.rb
126
- homepage: https://osdn.jp/projects/rutsubo/
148
+ homepage: https://github.com/dearblue/ruby-extzstd/
127
149
  licenses:
128
- - 2-clause BSD License
150
+ - BSD-2-Clause
129
151
  metadata: {}
130
152
  post_install_message:
131
153
  rdoc_options:
@@ -147,7 +169,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
147
169
  version: '0'
148
170
  requirements: []
149
171
  rubyforge_project:
150
- rubygems_version: 2.6.4
172
+ rubygems_version: 2.6.11
151
173
  signing_key:
152
174
  specification_version: 4
153
175
  summary: ruby bindings for Zstandard (zstd)
@@ -1,319 +0,0 @@
1
- /**
2
- * Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
3
- * All rights reserved.
4
- *
5
- * This source code is licensed under the BSD-style license found in the
6
- * LICENSE file in the root directory of this source tree. An additional grant
7
- * of patent rights can be found in the PATENTS file in the same directory.
8
- */
9
-
10
-
11
-
12
- /* *************************************
13
- * Dependencies
14
- ***************************************/
15
- #include <stdlib.h>
16
- #include "error_private.h"
17
- #include "zstd_internal.h" /* MIN, ZSTD_BLOCKHEADERSIZE, defaultCustomMem */
18
- #define ZBUFF_STATIC_LINKING_ONLY
19
- #include "zbuff.h"
20
-
21
-
22
- /* *************************************
23
- * Constants
24
- ***************************************/
25
- static size_t const ZBUFF_endFrameSize = ZSTD_BLOCKHEADERSIZE;
26
-
27
-
28
- /*-***********************************************************
29
- * Streaming compression
30
- *
31
- * A ZBUFF_CCtx object is required to track streaming operation.
32
- * Use ZBUFF_createCCtx() and ZBUFF_freeCCtx() to create/release resources.
33
- * Use ZBUFF_compressInit() to start a new compression operation.
34
- * ZBUFF_CCtx objects can be reused multiple times.
35
- *
36
- * Use ZBUFF_compressContinue() repetitively to consume your input.
37
- * *srcSizePtr and *dstCapacityPtr can be any size.
38
- * The function will report how many bytes were read or written by modifying *srcSizePtr and *dstCapacityPtr.
39
- * Note that it may not consume the entire input, in which case it's up to the caller to call again the function with remaining input.
40
- * The content of dst will be overwritten (up to *dstCapacityPtr) at each function call, so save its content if it matters or change dst .
41
- * @return : a hint to preferred nb of bytes to use as input for next function call (it's only a hint, to improve latency)
42
- * or an error code, which can be tested using ZBUFF_isError().
43
- *
44
- * ZBUFF_compressFlush() can be used to instruct ZBUFF to compress and output whatever remains within its buffer.
45
- * Note that it will not output more than *dstCapacityPtr.
46
- * Therefore, some content might still be left into its internal buffer if dst buffer is too small.
47
- * @return : nb of bytes still present into internal buffer (0 if it's empty)
48
- * or an error code, which can be tested using ZBUFF_isError().
49
- *
50
- * ZBUFF_compressEnd() instructs to finish a frame.
51
- * It will perform a flush and write frame epilogue.
52
- * Similar to ZBUFF_compressFlush(), it may not be able to output the entire internal buffer content if *dstCapacityPtr is too small.
53
- * @return : nb of bytes still present into internal buffer (0 if it's empty)
54
- * or an error code, which can be tested using ZBUFF_isError().
55
- *
56
- * Hint : recommended buffer sizes (not compulsory)
57
- * input : ZSTD_BLOCKSIZE_MAX (128 KB), internal unit size, it improves latency to use this value.
58
- * output : ZSTD_compressBound(ZSTD_BLOCKSIZE_MAX) + ZSTD_blockHeaderSize + ZBUFF_endFrameSize : ensures it's always possible to write/flush/end a full block at best speed.
59
- * ***********************************************************/
60
-
61
- typedef enum { ZBUFFcs_init, ZBUFFcs_load, ZBUFFcs_flush, ZBUFFcs_final } ZBUFF_cStage;
62
-
63
- /* *** Resources *** */
64
- struct ZBUFF_CCtx_s {
65
- ZSTD_CCtx* zc;
66
- char* inBuff;
67
- size_t inBuffSize;
68
- size_t inToCompress;
69
- size_t inBuffPos;
70
- size_t inBuffTarget;
71
- size_t blockSize;
72
- char* outBuff;
73
- size_t outBuffSize;
74
- size_t outBuffContentSize;
75
- size_t outBuffFlushedSize;
76
- ZBUFF_cStage stage;
77
- U32 checksum;
78
- U32 frameEnded;
79
- ZSTD_customMem customMem;
80
- }; /* typedef'd tp ZBUFF_CCtx within "zbuff.h" */
81
-
82
- ZBUFF_CCtx* ZBUFF_createCCtx(void)
83
- {
84
- return ZBUFF_createCCtx_advanced(defaultCustomMem);
85
- }
86
-
87
- ZBUFF_CCtx* ZBUFF_createCCtx_advanced(ZSTD_customMem customMem)
88
- {
89
- ZBUFF_CCtx* zbc;
90
-
91
- if (!customMem.customAlloc && !customMem.customFree)
92
- customMem = defaultCustomMem;
93
-
94
- if (!customMem.customAlloc || !customMem.customFree)
95
- return NULL;
96
-
97
- zbc = (ZBUFF_CCtx*)customMem.customAlloc(customMem.opaque, sizeof(ZBUFF_CCtx));
98
- if (zbc==NULL) return NULL;
99
- memset(zbc, 0, sizeof(ZBUFF_CCtx));
100
- memcpy(&zbc->customMem, &customMem, sizeof(ZSTD_customMem));
101
- zbc->zc = ZSTD_createCCtx_advanced(customMem);
102
- if (zbc->zc == NULL) { ZBUFF_freeCCtx(zbc); return NULL; }
103
- return zbc;
104
- }
105
-
106
- size_t ZBUFF_freeCCtx(ZBUFF_CCtx* zbc)
107
- {
108
- if (zbc==NULL) return 0; /* support free on NULL */
109
- ZSTD_freeCCtx(zbc->zc);
110
- if (zbc->inBuff) zbc->customMem.customFree(zbc->customMem.opaque, zbc->inBuff);
111
- if (zbc->outBuff) zbc->customMem.customFree(zbc->customMem.opaque, zbc->outBuff);
112
- zbc->customMem.customFree(zbc->customMem.opaque, zbc);
113
- return 0;
114
- }
115
-
116
-
117
- /* ====== Initialization ====== */
118
-
119
- size_t ZBUFF_compressInit_advanced(ZBUFF_CCtx* zbc,
120
- const void* dict, size_t dictSize,
121
- ZSTD_parameters params, unsigned long long pledgedSrcSize)
122
- {
123
- /* allocate buffers */
124
- { size_t const neededInBuffSize = (size_t)1 << params.cParams.windowLog;
125
- if (zbc->inBuffSize < neededInBuffSize) {
126
- zbc->inBuffSize = neededInBuffSize;
127
- zbc->customMem.customFree(zbc->customMem.opaque, zbc->inBuff); /* should not be necessary */
128
- zbc->inBuff = (char*)zbc->customMem.customAlloc(zbc->customMem.opaque, neededInBuffSize);
129
- if (zbc->inBuff == NULL) return ERROR(memory_allocation);
130
- }
131
- zbc->blockSize = MIN(ZSTD_BLOCKSIZE_ABSOLUTEMAX, neededInBuffSize);
132
- }
133
- if (zbc->outBuffSize < ZSTD_compressBound(zbc->blockSize)+1) {
134
- zbc->outBuffSize = ZSTD_compressBound(zbc->blockSize)+1;
135
- zbc->customMem.customFree(zbc->customMem.opaque, zbc->outBuff); /* should not be necessary */
136
- zbc->outBuff = (char*)zbc->customMem.customAlloc(zbc->customMem.opaque, zbc->outBuffSize);
137
- if (zbc->outBuff == NULL) return ERROR(memory_allocation);
138
- }
139
-
140
- { size_t const errorCode = ZSTD_compressBegin_advanced(zbc->zc, dict, dictSize, params, pledgedSrcSize);
141
- if (ZSTD_isError(errorCode)) return errorCode; }
142
-
143
- zbc->inToCompress = 0;
144
- zbc->inBuffPos = 0;
145
- zbc->inBuffTarget = zbc->blockSize;
146
- zbc->outBuffContentSize = zbc->outBuffFlushedSize = 0;
147
- zbc->stage = ZBUFFcs_load;
148
- zbc->checksum = params.fParams.checksumFlag > 0;
149
- zbc->frameEnded = 0;
150
- return 0; /* ready to go */
151
- }
152
-
153
-
154
- size_t ZBUFF_compressInitDictionary(ZBUFF_CCtx* zbc, const void* dict, size_t dictSize, int compressionLevel)
155
- {
156
- ZSTD_parameters const params = ZSTD_getParams(compressionLevel, 0, dictSize);
157
- return ZBUFF_compressInit_advanced(zbc, dict, dictSize, params, 0);
158
- }
159
-
160
- size_t ZBUFF_compressInit(ZBUFF_CCtx* zbc, int compressionLevel)
161
- {
162
- return ZBUFF_compressInitDictionary(zbc, NULL, 0, compressionLevel);
163
- }
164
-
165
-
166
- /* internal util function */
167
- MEM_STATIC size_t ZBUFF_limitCopy(void* dst, size_t dstCapacity, const void* src, size_t srcSize)
168
- {
169
- size_t const length = MIN(dstCapacity, srcSize);
170
- memcpy(dst, src, length);
171
- return length;
172
- }
173
-
174
-
175
- /* ====== Compression ====== */
176
-
177
- typedef enum { zbf_gather, zbf_flush, zbf_end } ZBUFF_flush_e;
178
-
179
- static size_t ZBUFF_compressContinue_generic(ZBUFF_CCtx* zbc,
180
- void* dst, size_t* dstCapacityPtr,
181
- const void* src, size_t* srcSizePtr,
182
- ZBUFF_flush_e const flush)
183
- {
184
- U32 someMoreWork = 1;
185
- const char* const istart = (const char*)src;
186
- const char* const iend = istart + *srcSizePtr;
187
- const char* ip = istart;
188
- char* const ostart = (char*)dst;
189
- char* const oend = ostart + *dstCapacityPtr;
190
- char* op = ostart;
191
-
192
- while (someMoreWork) {
193
- switch(zbc->stage)
194
- {
195
- case ZBUFFcs_init: return ERROR(init_missing); /* call ZBUFF_compressInit() first ! */
196
-
197
- case ZBUFFcs_load:
198
- /* complete inBuffer */
199
- { size_t const toLoad = zbc->inBuffTarget - zbc->inBuffPos;
200
- size_t const loaded = ZBUFF_limitCopy(zbc->inBuff + zbc->inBuffPos, toLoad, ip, iend-ip);
201
- zbc->inBuffPos += loaded;
202
- ip += loaded;
203
- if ( (zbc->inBuffPos==zbc->inToCompress) || (!flush && (toLoad != loaded)) ) {
204
- someMoreWork = 0; break; /* not enough input to get a full block : stop there, wait for more */
205
- } }
206
- /* compress current block (note : this stage cannot be stopped in the middle) */
207
- { void* cDst;
208
- size_t cSize;
209
- size_t const iSize = zbc->inBuffPos - zbc->inToCompress;
210
- size_t oSize = oend-op;
211
- if (oSize >= ZSTD_compressBound(iSize))
212
- cDst = op; /* compress directly into output buffer (avoid flush stage) */
213
- else
214
- cDst = zbc->outBuff, oSize = zbc->outBuffSize;
215
- cSize = (flush == zbf_end) ?
216
- ZSTD_compressEnd(zbc->zc, cDst, oSize, zbc->inBuff + zbc->inToCompress, iSize) :
217
- ZSTD_compressContinue(zbc->zc, cDst, oSize, zbc->inBuff + zbc->inToCompress, iSize);
218
- if (ZSTD_isError(cSize)) return cSize;
219
- if (flush == zbf_end) zbc->frameEnded = 1;
220
- /* prepare next block */
221
- zbc->inBuffTarget = zbc->inBuffPos + zbc->blockSize;
222
- if (zbc->inBuffTarget > zbc->inBuffSize)
223
- zbc->inBuffPos = 0, zbc->inBuffTarget = zbc->blockSize; /* note : inBuffSize >= blockSize */
224
- zbc->inToCompress = zbc->inBuffPos;
225
- if (cDst == op) { op += cSize; break; } /* no need to flush */
226
- zbc->outBuffContentSize = cSize;
227
- zbc->outBuffFlushedSize = 0;
228
- zbc->stage = ZBUFFcs_flush; /* continue to flush stage */
229
- }
230
-
231
- case ZBUFFcs_flush:
232
- { size_t const toFlush = zbc->outBuffContentSize - zbc->outBuffFlushedSize;
233
- size_t const flushed = ZBUFF_limitCopy(op, oend-op, zbc->outBuff + zbc->outBuffFlushedSize, toFlush);
234
- op += flushed;
235
- zbc->outBuffFlushedSize += flushed;
236
- if (toFlush!=flushed) { someMoreWork = 0; break; } /* dst too small to store flushed data : stop there */
237
- zbc->outBuffContentSize = zbc->outBuffFlushedSize = 0;
238
- zbc->stage = ZBUFFcs_load;
239
- break;
240
- }
241
-
242
- case ZBUFFcs_final:
243
- someMoreWork = 0; /* do nothing */
244
- break;
245
-
246
- default:
247
- return ERROR(GENERIC); /* impossible */
248
- }
249
- }
250
-
251
- *srcSizePtr = ip - istart;
252
- *dstCapacityPtr = op - ostart;
253
- if (zbc->frameEnded) return 0;
254
- { size_t hintInSize = zbc->inBuffTarget - zbc->inBuffPos;
255
- if (hintInSize==0) hintInSize = zbc->blockSize;
256
- return hintInSize;
257
- }
258
- }
259
-
260
- size_t ZBUFF_compressContinue(ZBUFF_CCtx* zbc,
261
- void* dst, size_t* dstCapacityPtr,
262
- const void* src, size_t* srcSizePtr)
263
- {
264
- return ZBUFF_compressContinue_generic(zbc, dst, dstCapacityPtr, src, srcSizePtr, zbf_gather);
265
- }
266
-
267
-
268
-
269
- /* ====== Finalize ====== */
270
-
271
- size_t ZBUFF_compressFlush(ZBUFF_CCtx* zbc, void* dst, size_t* dstCapacityPtr)
272
- {
273
- size_t srcSize = 0;
274
- ZBUFF_compressContinue_generic(zbc, dst, dstCapacityPtr, &srcSize, &srcSize, zbf_flush); /* use a valid src address instead of NULL */
275
- return zbc->outBuffContentSize - zbc->outBuffFlushedSize;
276
- }
277
-
278
-
279
- size_t ZBUFF_compressEnd(ZBUFF_CCtx* zbc, void* dst, size_t* dstCapacityPtr)
280
- {
281
- BYTE* const ostart = (BYTE*)dst;
282
- BYTE* const oend = ostart + *dstCapacityPtr;
283
- BYTE* op = ostart;
284
-
285
- if (zbc->stage != ZBUFFcs_final) {
286
- /* flush whatever remains */
287
- size_t outSize = *dstCapacityPtr;
288
- size_t srcSize = 0;
289
- size_t const notEnded = ZBUFF_compressContinue_generic(zbc, dst, &outSize, &srcSize, &srcSize, zbf_end); /* use a valid address instead of NULL */
290
- size_t const remainingToFlush = zbc->outBuffContentSize - zbc->outBuffFlushedSize;
291
- op += outSize;
292
- if (remainingToFlush) {
293
- *dstCapacityPtr = op-ostart;
294
- return remainingToFlush + ZBUFF_endFrameSize + (zbc->checksum * 4);
295
- }
296
- /* create epilogue */
297
- zbc->stage = ZBUFFcs_final;
298
- zbc->outBuffContentSize = !notEnded ? 0 :
299
- ZSTD_compressEnd(zbc->zc, zbc->outBuff, zbc->outBuffSize, NULL, 0); /* write epilogue into outBuff */
300
- }
301
-
302
- /* flush epilogue */
303
- { size_t const toFlush = zbc->outBuffContentSize - zbc->outBuffFlushedSize;
304
- size_t const flushed = ZBUFF_limitCopy(op, oend-op, zbc->outBuff + zbc->outBuffFlushedSize, toFlush);
305
- op += flushed;
306
- zbc->outBuffFlushedSize += flushed;
307
- *dstCapacityPtr = op-ostart;
308
- if (toFlush==flushed) zbc->stage = ZBUFFcs_init; /* end reached */
309
- return toFlush - flushed;
310
- }
311
- }
312
-
313
-
314
-
315
- /* *************************************
316
- * Tool functions
317
- ***************************************/
318
- size_t ZBUFF_recommendedCInSize(void) { return ZSTD_BLOCKSIZE_ABSOLUTEMAX; }
319
- size_t ZBUFF_recommendedCOutSize(void) { return ZSTD_compressBound(ZSTD_BLOCKSIZE_ABSOLUTEMAX) + ZSTD_blockHeaderSize + ZBUFF_endFrameSize; }