ruby-zstds 1.0.1 → 1.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 02550c140ef2cb895c77f3db452db70cd5bead01cf8475953cf805ded512b278
4
- data.tar.gz: 3598ef3c1805820db6c72b9e6abec6580255ca4784c3f83a8f0d39138e242895
3
+ metadata.gz: 359ef05325e4af260831df1c3d71b70d64d1b4f235631ad3cd0bf10be63be308
4
+ data.tar.gz: 39b138930c23a914317db548081db091a607b00867300788d3de3c22e7e56616
5
5
  SHA512:
6
- metadata.gz: dadda36de3e6e831cbd2a6e18b49268d6d92bb978709f2818ebe6b23af29d30e202365b3a974475a4408c076f7b0249948808556872af30c350affb779504f12
7
- data.tar.gz: 605cb7e350b0d61b9d947ad307e39366af37f3b5bca05f649a1bda89b565743777e14199949580da07120f8dd5b8b0284e8ebd2948375eab394e4e32482ad325
6
+ metadata.gz: 0c76ce3fe240fb963dab49e55ff167a2cfea690e1bb48b107d164821d5bba1b5090eb81b73ec221a86aa4c94c05f9082d540d6c0423ae99326face5deee199d8
7
+ data.tar.gz: 00db3a70938e3ca436d253f9c2e715941837c252569bb6d72d1ddb94b1c8c9e85aeeb1bd67e9c85a0ab965c5393f785f273e67a0a3869a1ae770a915ae23ca9e
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # Ruby bindings for zstd library
2
2
 
3
- | Travis | AppVeyor | Cirrus | Circle |
4
- | :---: | :---: | :---: | :---: |
5
- | [![Travis test status](https://travis-ci.com/andrew-aladev/ruby-zstds.svg?branch=master)](https://travis-ci.com/andrew-aladev/ruby-zstds) | [![AppVeyor test status](https://ci.appveyor.com/api/projects/status/github/andrew-aladev/ruby-zstds?branch=master&svg=true)](https://ci.appveyor.com/project/andrew-aladev/ruby-zstds/branch/master) | [![Cirrus test status](https://api.cirrus-ci.com/github/andrew-aladev/ruby-zstds.svg?branch=master)](https://cirrus-ci.com/github/andrew-aladev/ruby-zstds) | [![Circle test status](https://circleci.com/gh/andrew-aladev/ruby-zstds/tree/master.svg?style=shield)](https://circleci.com/gh/andrew-aladev/ruby-zstds/tree/master) |
3
+ | Travis | AppVeyor | Circle | Codecov |
4
+ | :---: | :---: | :---: | :---: |
5
+ | [![Travis test status](https://travis-ci.com/andrew-aladev/ruby-zstds.svg?branch=master)](https://travis-ci.com/andrew-aladev/ruby-zstds) | [![AppVeyor test status](https://ci.appveyor.com/api/projects/status/github/andrew-aladev/ruby-zstds?branch=master&svg=true)](https://ci.appveyor.com/project/andrew-aladev/ruby-zstds/branch/master) | [![Circle test status](https://circleci.com/gh/andrew-aladev/ruby-zstds/tree/master.svg?style=shield)](https://circleci.com/gh/andrew-aladev/ruby-zstds/tree/master) | [![Codecov](https://codecov.io/gh/andrew-aladev/ruby-zstds/branch/master/graph/badge.svg)](https://codecov.io/gh/andrew-aladev/ruby-zstds) |
6
6
 
7
7
  See [zstd library](https://github.com/facebook/zstd).
8
8
 
@@ -21,6 +21,8 @@ rake gem
21
21
  gem install pkg/ruby-zstds-*.gem
22
22
  ```
23
23
 
24
+ You can also use [overlay](https://github.com/andrew-aladev/overlay) for gentoo.
25
+
24
26
  ## Usage
25
27
 
26
28
  There are simple APIs: `String` and `File`. Also you can use generic streaming API: `Stream::Writer` and `Stream::Reader`.
@@ -36,6 +38,27 @@ ZSTDS::File.decompress "file.txt.zst", "file.txt"
36
38
 
37
39
  ZSTDS::Stream::Writer.open("file.txt.zst") { |writer| writer << "sample string" }
38
40
  puts ZSTDS::Stream::Reader.open("file.txt.zst") { |reader| reader.read }
41
+
42
+ writer = ZSTDS::Stream::Writer.new output_socket
43
+ begin
44
+ bytes_written = writer.write_nonblock "sample string"
45
+ # handle "bytes_written"
46
+ rescue IO::WaitWritable
47
+ # handle wait
48
+ ensure
49
+ writer.close
50
+ end
51
+
52
+ reader = ZSTDS::Stream::Reader.new input_socket
53
+ begin
54
+ puts reader.read_nonblock(512)
55
+ rescue IO::WaitReadable
56
+ # handle wait
57
+ rescue ::EOFError
58
+ # handle eof
59
+ ensure
60
+ reader.close
61
+ end
39
62
  ```
40
63
 
41
64
  You can create dictionary using `ZSTDS::Dictionary`.
@@ -80,158 +103,64 @@ end
80
103
 
81
104
  ## Options
82
105
 
83
- Each API supports several options:
84
-
85
- ```
86
- :source_buffer_length
87
- :destination_buffer_length
88
- ```
106
+ | Option | Values | Default | Description |
107
+ |---------------------------------|----------------|------------|-------------|
108
+ | `source_buffer_length` | 0 - inf | 0 (auto) | internal buffer length for source data |
109
+ | `destination_buffer_length` | 0 - inf | 0 (auto) | internal buffer length for description data |
110
+ | `compression_level` | -131072 - 22 | 0 (auto) | compression level |
111
+ | `window_log` | 10 - 31 | 0 (auto) | maximum back-reference distance (power of 2) |
112
+ | `hash_log` | 6 - 30 | 0 (auto) | size of the initial probe table (power of 2) |
113
+ | `chain_log` | 6 - 30 | 0 (auto) | size of the multi-probe search table (power of 2) |
114
+ | `search_log` | 1 - 30 | 0 (auto) | number of search attempts (power of 2) |
115
+ | `min_match` | 3 - 7 | 0 (auto) | minimum size of searched matches |
116
+ | `target_length` | 0 - 131072 | 0 (auto) | distance between match sampling (for `:fast` strategy), length of match considered "good enough" for (for other strategies) |
117
+ | `strategy` | `STRATEGIES` | nil (auto) | choses strategy |
118
+ | `enable_long_distance_matching` | true/false | nil (auto) | enables long distance matching |
119
+ | `ldm_hash_log` | 6 - 30 | 0 (auto) | size of the table for long distance matching (power of 2) |
120
+ | `ldm_min_match` | 4 - 4096 | 0 (auto) | minimum match size for long distance matcher |
121
+ | `ldm_bucket_size_log` | 1 - 8 | 0 (auto) | log size of each bucket in the LDM hash table for collision resolution |
122
+ | `ldm_hash_rate_log` | 0 - 25 | 0 (auto) | frequency of inserting/looking up entries into the LDM hash table |
123
+ | `content_size_flag` | true/false | true | enables writing of content size into frame header (if known) |
124
+ | `checksum_flag` | true/false | false | enables writing of 32-bits checksum of content at end of frame |
125
+ | `dict_id_flag` | true/false | true | enables writing of dictionary id into frame header |
126
+ | `nb_workers` | 0 - 200 | 0 (auto) | number of threads spawned in parallel |
127
+ | `job_size` | 0 - 1073741824 | 0 (auto) | size of job (nb_workers >= 1) |
128
+ | `overlap_log` | 0 - 9 | 0 (auto) | overlap size, as a fraction of window size |
129
+ | `window_log_max` | 10 - 31 | 0 (auto) | size limit (power of 2) |
130
+ | `dictionary` | `Dictionary` | nil | chose dictionary |
131
+ | `pledged_size` | 0 - inf | 0 (auto) | size of input (if known) |
89
132
 
90
133
  There are internal buffers for compressed and decompressed data.
91
- For example you want to use 1 KB as source buffer length for compressor - please use 256 B as destination buffer length.
92
- You want to use 256 B as source buffer length for decompressor - please use 1 KB as destination buffer length.
93
-
94
- Values: 0 - infinity, default value: 0.
95
- 0 means automatic buffer length selection.
96
-
97
- ```
98
- :compression_level
99
- ```
100
-
101
- Values: `ZSTDS::Option::MIN_COMPRESSION_LEVEL` - `ZSTDS::Option::MAX_COMPRESSION_LEVEL`, default value: `0`.
102
-
103
- ```
104
- :window_log
105
- ```
106
-
107
- Values: `ZSTDS::Option::MIN_WINDOW_LOG` - `ZSTDS::Option::MAX_WINDOW_LOG`, default value: `0`.
108
-
109
- ```
110
- :hash_log
111
- ```
112
-
113
- Values: `ZSTDS::Option::MIN_HASH_LOG` - `ZSTDS::Option::MAX_HASH_LOG`, default value: `0`.
114
-
115
- ```
116
- :chain_log
117
- ```
118
-
119
- Values: `ZSTDS::Option::MIN_CHAIN_LOG` - `ZSTDS::Option::MAX_CHAIN_LOG`, default value: `0`.
120
-
121
- ```
122
- :search_log
123
- ```
124
-
125
- Values: `ZSTDS::Option::MIN_SEARCH_LOG` - `ZSTDS::Option::MAX_SEARCH_LOG`, default value: `0`.
126
-
127
- ```
128
- :min_match
129
- ```
130
-
131
- Values: `ZSTDS::Option::MIN_MIN_MATCH` - `ZSTDS::Option::MAX_MIN_MATCH`, default value: `0`.
132
-
133
- ```
134
- :target_length
135
- ```
136
-
137
- Values: `ZSTDS::Option::MIN_TARGET_LENGTH` - `ZSTDS::Option::MAX_TARGET_LENGTH`, default value: `0`.
138
-
139
- ```
140
- :strategy
141
- ```
142
-
143
- Values: `ZSTDS::Option::STRATEGIES`, default value: none.
144
-
145
- ```
146
- :enable_long_distance_matching
147
- ```
148
-
149
- Values: true/false, default value: none.
150
-
151
- ```
152
- :ldm_hash_log
153
- ```
154
-
155
- Values: `ZSTDS::Option::MIN_LDM_HASH_LOG` - `ZSTDS::Option::MAX_LDM_HASH_LOG`, default value: `0`.
156
-
157
- ```
158
- :ldm_min_match
159
- ```
160
-
161
- Values: `ZSTDS::Option::MIN_LDM_MIN_MATCH` - `ZSTDS::Option::MAX_LDM_MIN_MATCH`, default value: `0`.
162
-
163
- ```
164
- :ldm_bucket_size_log
165
- ```
166
-
167
- Values: `ZSTDS::Option::MIN_LDM_BUCKET_SIZE_LOG` - `ZSTDS::Option::MAX_LDM_BUCKET_SIZE_LOG`, default value: `0`.
168
-
169
- ```
170
- :ldm_hash_rate_log
171
- ```
172
-
173
- Values: `ZSTDS::Option::MIN_LDM_HASH_RATE_LOG` - `ZSTDS::Option::MAX_LDM_HASH_RATE_LOG`, default value: `0`.
174
-
175
- ```
176
- :content_size_flag
177
- ```
178
-
179
- Values: true/false, default value: true.
180
-
181
- ```
182
- :checksum_flag
183
- ```
184
-
185
- Values: true/false, default value: false.
186
-
187
- ```
188
- :dict_id_flag
189
- ```
190
-
191
- Values: true/false, default value: true.
192
-
193
- ```
194
- :nb_workers
195
- ```
196
-
197
- Values: `ZSTDS::Option::MIN_NB_WORKERS` - `ZSTDS::Option::MAX_NB_WORKERS`, default value: `0`.
198
-
199
- ```
200
- :job_size
201
- ```
202
-
203
- Values: `ZSTDS::Option::MIN_JOB_SIZE` - `ZSTDS::Option::MAX_JOB_SIZE`, default value: `0`.
134
+ For example you want to use 1 KB as `source_buffer_length` for compressor - please use 256 B as `destination_buffer_length`.
135
+ You want to use 256 B as `source_buffer_length` for decompressor - please use 1 KB as `destination_buffer_length`.
204
136
 
205
- ```
206
- :overlap_log
207
- ```
208
-
209
- Values: `ZSTDS::Option::MIN_OVERLAP_LOG` - `ZSTDS::Option::MAX_OVERLAP_LOG`, default value: `0`.
210
-
211
- ```
212
- :window_log_max
213
- ```
214
-
215
- Values: `ZSTDS::Option::MIN_WINDOW_LOG_MAX` - `ZSTDS::Option::MAX_WINDOW_LOG_MAX`, default value: `0`.
216
-
217
- ```
218
- :dictionary
219
- ```
220
-
221
- Special option for dictionary, default value: none.
222
-
223
- ```
224
- :pledged_size
225
- ```
226
-
227
- Values: 0 - infinity, default value: 0.
228
- It is reasonable to provide size of input (if known) for streaming api.
229
137
  `String` and `File` will set `:pledged_size` automaticaly.
230
138
 
231
- Please read zstd docs for more info about options.
139
+ You can also read zstd docs for more info about options.
140
+
141
+ | Option | Related constants |
142
+ |-----------------------|-------------------|
143
+ | `compression_level` | `ZSTDS::Option::MIN_COMPRESSION_LEVEL` = -131072, `ZSTDS::Option::MAX_COMPRESSION_LEVEL` = 22 |
144
+ | `window_log` | `ZSTDS::Option::MIN_WINDOW_LOG` = 10, `ZSTDS::Option::MAX_WINDOW_LOG` = 31 |
145
+ | `hash_log` | `ZSTDS::Option::MIN_HASH_LOG` = 6, `ZSTDS::Option::MAX_HASH_LOG` = 30 |
146
+ | `chain_log` | `ZSTDS::Option::MIN_CHAIN_LOG` = 6, `ZSTDS::Option::MAX_CHAIN_LOG` = 30 |
147
+ | `search_log` | `ZSTDS::Option::MIN_SEARCH_LOG` = 1, `ZSTDS::Option::MAX_SEARCH_LOG` = 30 |
148
+ | `min_match` | `ZSTDS::Option::MIN_MIN_MATCH` = 3, `ZSTDS::Option::MAX_MIN_MATCH` = 7 |
149
+ | `target_length` | `ZSTDS::Option::MIN_TARGET_LENGTH` = 0, `ZSTDS::Option::MAX_TARGET_LENGTH` = 131072 |
150
+ | `strategy` | `ZSTDS::Option::STRATEGIES` = `%i[fast dfast greedy lazy lazy2 btlazy2 btopt btultra btultra2]` |
151
+ | `ldm_hash_log` | `ZSTDS::Option::MIN_LDM_HASH_LOG` = 6, `ZSTDS::Option::MAX_LDM_HASH_LOG` = 30 |
152
+ | `ldm_min_match` | `ZSTDS::Option::MIN_LDM_MIN_MATCH` = 4, `ZSTDS::Option::MAX_LDM_MIN_MATCH` = 4096 |
153
+ | `ldm_bucket_size_log` | `ZSTDS::Option::MIN_LDM_BUCKET_SIZE_LOG` = 1, `ZSTDS::Option::MAX_LDM_BUCKET_SIZE_LOG` = 8 |
154
+ | `ldm_hash_rate_log` | `ZSTDS::Option::MIN_LDM_HASH_RATE_LOG` = 0, `ZSTDS::Option::MAX_LDM_HASH_RATE_LOG` = 25 |
155
+ | `nb_workers` | `ZSTDS::Option::MIN_NB_WORKERS` = 0, `ZSTDS::Option::MAX_NB_WORKERS` = 200 |
156
+ | `job_size` | `ZSTDS::Option::MIN_JOB_SIZE` = 0, `ZSTDS::Option::MAX_JOB_SIZE` = 1073741824 |
157
+ | `overlap_log` | `ZSTDS::Option::MIN_OVERLAP_LOG` = 0, `ZSTDS::Option::MAX_OVERLAP_LOG` = 9 |
158
+ | `window_log_max` | `ZSTDS::Option::MIN_WINDOW_LOG_MAX` = 10, `ZSTDS::Option::MAX_WINDOW_LOG_MAX` = 31 |
232
159
 
233
160
  Possible compressor options:
234
161
  ```
162
+ :source_buffer_length
163
+ :destination_buffer_length
235
164
  :compression_level
236
165
  :window_log
237
166
  :hash_log
@@ -257,6 +186,8 @@ Possible compressor options:
257
186
 
258
187
  Possible decompressor options:
259
188
  ```
189
+ :source_buffer_length
190
+ :destination_buffer_length
260
191
  :window_log_max
261
192
  :dictionary
262
193
  ```
@@ -306,7 +237,7 @@ File maintains both source and destination buffers, it accepts both `source_buff
306
237
 
307
238
  ## Stream::Writer
308
239
 
309
- Its behaviour is similar to builtin [`Zlib::GzipWriter`](https://ruby-doc.org/stdlib-2.6.1/libdoc/zlib/rdoc/Zlib/GzipWriter.html).
240
+ Its behaviour is similar to builtin [`Zlib::GzipWriter`](https://ruby-doc.org/stdlib-2.7.0/libdoc/zlib/rdoc/Zlib/GzipWriter.html).
310
241
 
311
242
  Writer maintains destination buffer only, so it accepts `destination_buffer_length` option only.
312
243
 
@@ -344,7 +275,7 @@ Set another encodings, `nil` is just for compatibility with `IO`.
344
275
  #tell
345
276
  ```
346
277
 
347
- See [`IO`](https://ruby-doc.org/core-2.6.1/IO.html) docs.
278
+ See [`IO`](https://ruby-doc.org/core-2.7.0/IO.html) docs.
348
279
 
349
280
  ```
350
281
  #write(*objects)
@@ -354,7 +285,7 @@ See [`IO`](https://ruby-doc.org/core-2.6.1/IO.html) docs.
354
285
  #closed?
355
286
  ```
356
287
 
357
- See [`Zlib::GzipWriter`](https://ruby-doc.org/stdlib-2.6.1/libdoc/zlib/rdoc/Zlib/GzipWriter.html) docs.
288
+ See [`Zlib::GzipWriter`](https://ruby-doc.org/stdlib-2.7.0/libdoc/zlib/rdoc/Zlib/GzipWriter.html) docs.
358
289
 
359
290
  ```
360
291
  #write_nonblock(object, *options)
@@ -376,11 +307,11 @@ Behaviour is the same as `IO#write_nonblock` method.
376
307
  #puts(*objects)
377
308
  ```
378
309
 
379
- Typical helpers, see [`Zlib::GzipWriter`](https://ruby-doc.org/stdlib-2.6.1/libdoc/zlib/rdoc/Zlib/GzipWriter.html) docs.
310
+ Typical helpers, see [`Zlib::GzipWriter`](https://ruby-doc.org/stdlib-2.7.0/libdoc/zlib/rdoc/Zlib/GzipWriter.html) docs.
380
311
 
381
312
  ## Stream::Reader
382
313
 
383
- Its behaviour is similar to builtin [`Zlib::GzipReader`](https://ruby-doc.org/stdlib-2.6.1/libdoc/zlib/rdoc/Zlib/GzipReader.html).
314
+ Its behaviour is similar to builtin [`Zlib::GzipReader`](https://ruby-doc.org/stdlib-2.7.0/libdoc/zlib/rdoc/Zlib/GzipReader.html).
384
315
 
385
316
  Reader maintains both source and destination buffers, it accepts both `source_buffer_length` and `destination_buffer_length` options.
386
317
 
@@ -415,7 +346,7 @@ Set another encodings.
415
346
  #tell
416
347
  ```
417
348
 
418
- See [`IO`](https://ruby-doc.org/core-2.6.1/IO.html) docs.
349
+ See [`IO`](https://ruby-doc.org/core-2.7.0/IO.html) docs.
419
350
 
420
351
  ```
421
352
  #read(bytes_to_read = nil, out_buffer = nil)
@@ -425,14 +356,14 @@ See [`IO`](https://ruby-doc.org/core-2.6.1/IO.html) docs.
425
356
  #closed?
426
357
  ```
427
358
 
428
- See [`Zlib::GzipReader`](https://ruby-doc.org/stdlib-2.6.1/libdoc/zlib/rdoc/Zlib/GzipReader.html) docs.
359
+ See [`Zlib::GzipReader`](https://ruby-doc.org/stdlib-2.7.0/libdoc/zlib/rdoc/Zlib/GzipReader.html) docs.
429
360
 
430
361
  ```
431
362
  #readpartial(bytes_to_read = nil, out_buffer = nil)
432
363
  #read_nonblock(bytes_to_read, out_buffer = nil, *options)
433
364
  ```
434
365
 
435
- See [`IO`](https://ruby-doc.org/core-2.6.1/IO.html) docs.
366
+ See [`IO`](https://ruby-doc.org/core-2.7.0/IO.html) docs.
436
367
 
437
368
  ```
438
369
  #getbyte
@@ -455,7 +386,7 @@ See [`IO`](https://ruby-doc.org/core-2.6.1/IO.html) docs.
455
386
  #ungetline(line)
456
387
  ```
457
388
 
458
- Typical helpers, see [`Zlib::GzipReader`](https://ruby-doc.org/stdlib-2.6.1/libdoc/zlib/rdoc/Zlib/GzipReader.html) docs.
389
+ Typical helpers, see [`Zlib::GzipReader`](https://ruby-doc.org/stdlib-2.7.0/libdoc/zlib/rdoc/Zlib/GzipReader.html) docs.
459
390
 
460
391
  ## Dictionary
461
392
 
@@ -489,9 +420,9 @@ Read dictionary id from buffer.
489
420
 
490
421
  ## CI
491
422
 
492
- Travis and Appveyor CI uses [scripts/ci_test.sh](scripts/ci_test.sh) directly.
493
- Cirrus and Circle CI uses prebuilt [scripts/test-images](scripts/test-images).
494
- Cirrus CI uses amd64 image, Circle CI - i686.
423
+ See universal test script [scripts/ci_test.sh](scripts/ci_test.sh) for CI.
424
+ Please visit [scripts/test-images](scripts/test-images).
425
+ You can run this test script using many native and cross images.
495
426
 
496
427
  ## License
497
428
 
@@ -75,7 +75,20 @@ $srcs = %w[
75
75
  .map { |name| "src/#{extension_name}/#{name}.c" }
76
76
  .freeze
77
77
 
78
+ # Removing library duplicates.
79
+ $libs = $libs.split(%r{\s})
80
+ .reject(&:empty?)
81
+ .sort
82
+ .uniq
83
+ .join " "
84
+
85
+ if ENV["CI"] || ENV["COVERAGE"]
86
+ $CFLAGS << " --coverage"
87
+ $LDFLAGS << " --coverage"
88
+ end
89
+
78
90
  $CFLAGS << " -Wno-declaration-after-statement"
91
+
79
92
  $VPATH << "$(srcdir)/#{extension_name}:$(srcdir)/#{extension_name}/stream"
80
93
  # rubocop:enable Style/GlobalVars
81
94
 
@@ -13,4 +13,7 @@
13
13
  typedef size_t zstds_result_t;
14
14
  typedef uint_fast8_t zstds_ext_result_t;
15
15
 
16
+ typedef uint8_t zstds_ext_byte_t;
17
+ typedef uint_fast8_t zstds_ext_byte_fast_t;
18
+
16
19
  #endif // ZSTDS_EXT_COMMON_H
@@ -3,14 +3,11 @@
3
3
 
4
4
  #include "zstds_ext/dictionary.h"
5
5
 
6
- #include <stdint.h>
7
- #include <stdlib.h>
8
6
  #include <string.h>
9
7
  #include <zdict.h>
10
8
 
11
9
  #include "ruby.h"
12
10
  #include "zstds_ext/buffer.h"
13
- #include "zstds_ext/common.h"
14
11
  #include "zstds_ext/error.h"
15
12
  #include "zstds_ext/macro.h"
16
13
  #include "zstds_ext/option.h"
@@ -54,7 +51,7 @@ VALUE zstds_ext_train_dictionary_buffer(VALUE ZSTDS_EXT_UNUSED(self), VALUE samp
54
51
  zstds_ext_raise_error(ZSTDS_EXT_ERROR_ALLOCATE_FAILED);
55
52
  }
56
53
 
57
- uint8_t* samples_buffer = malloc(samples_size);
54
+ zstds_ext_byte_t* samples_buffer = malloc(samples_size);
58
55
  if (samples_buffer == NULL) {
59
56
  zstds_ext_raise_error(ZSTDS_EXT_ERROR_ALLOCATE_FAILED);
60
57
  }
@@ -6,7 +6,6 @@
6
6
  #include <zstd_errors.h>
7
7
 
8
8
  #include "ruby.h"
9
- #include "zstds_ext/common.h"
10
9
 
11
10
  zstds_ext_result_t zstds_ext_get_error(ZSTD_ErrorCode error_code)
12
11
  {
@@ -3,14 +3,11 @@
3
3
 
4
4
  #include "ruby/io.h"
5
5
 
6
- #include <stdint.h>
7
6
  #include <stdio.h>
8
- #include <stdlib.h>
9
7
  #include <string.h>
10
8
  #include <zstd.h>
11
9
 
12
10
  #include "ruby.h"
13
- #include "zstds_ext/common.h"
14
11
  #include "zstds_ext/error.h"
15
12
  #include "zstds_ext/io.h"
16
13
  #include "zstds_ext/macro.h"
@@ -23,7 +20,7 @@ enum {
23
20
 
24
21
  // -- file --
25
22
 
26
- static inline zstds_ext_result_t read_file(FILE* source_file, uint8_t* source_buffer, size_t* source_length_ptr, size_t source_buffer_length)
23
+ static inline zstds_ext_result_t read_file(FILE* source_file, zstds_ext_byte_t* source_buffer, size_t* source_length_ptr, size_t source_buffer_length)
27
24
  {
28
25
  size_t read_length = fread(source_buffer, 1, source_buffer_length, source_file);
29
26
  if (read_length == 0 && feof(source_file)) {
@@ -39,7 +36,7 @@ static inline zstds_ext_result_t read_file(FILE* source_file, uint8_t* source_bu
39
36
  return 0;
40
37
  }
41
38
 
42
- static inline zstds_ext_result_t write_file(FILE* destination_file, uint8_t* destination_buffer, size_t destination_length)
39
+ static inline zstds_ext_result_t write_file(FILE* destination_file, zstds_ext_byte_t* destination_buffer, size_t destination_length)
43
40
  {
44
41
  size_t written_length = fwrite(destination_buffer, 1, destination_length, destination_file);
45
42
  if (written_length != destination_length) {
@@ -52,15 +49,15 @@ static inline zstds_ext_result_t write_file(FILE* destination_file, uint8_t* des
52
49
  // -- buffer --
53
50
 
54
51
  static inline zstds_ext_result_t create_buffers(
55
- uint8_t** source_buffer_ptr, size_t source_buffer_length,
56
- uint8_t** destination_buffer_ptr, size_t destination_buffer_length)
52
+ zstds_ext_byte_t** source_buffer_ptr, size_t source_buffer_length,
53
+ zstds_ext_byte_t** destination_buffer_ptr, size_t destination_buffer_length)
57
54
  {
58
- uint8_t* source_buffer = malloc(source_buffer_length);
55
+ zstds_ext_byte_t* source_buffer = malloc(source_buffer_length);
59
56
  if (source_buffer == NULL) {
60
57
  return ZSTDS_EXT_ERROR_ALLOCATE_FAILED;
61
58
  }
62
59
 
63
- uint8_t* destination_buffer = malloc(destination_buffer_length);
60
+ zstds_ext_byte_t* destination_buffer = malloc(destination_buffer_length);
64
61
  if (destination_buffer == NULL) {
65
62
  free(source_buffer);
66
63
  return ZSTDS_EXT_ERROR_ALLOCATE_FAILED;
@@ -79,12 +76,12 @@ static inline zstds_ext_result_t create_buffers(
79
76
  // Algorithm can use same buffer again.
80
77
 
81
78
  static inline zstds_ext_result_t read_more_source(
82
- FILE* source_file,
83
- const uint8_t** source_ptr, size_t* source_length_ptr,
84
- uint8_t* source_buffer, size_t source_buffer_length)
79
+ FILE* source_file,
80
+ const zstds_ext_byte_t** source_ptr, size_t* source_length_ptr,
81
+ zstds_ext_byte_t* source_buffer, size_t source_buffer_length)
85
82
  {
86
- const uint8_t* source = *source_ptr;
87
- size_t source_length = *source_length_ptr;
83
+ const zstds_ext_byte_t* source = *source_ptr;
84
+ size_t source_length = *source_length_ptr;
88
85
 
89
86
  if (source != source_buffer) {
90
87
  if (source_length != 0) {
@@ -101,8 +98,8 @@ static inline zstds_ext_result_t read_more_source(
101
98
  return ZSTDS_EXT_ERROR_NOT_ENOUGH_SOURCE_BUFFER;
102
99
  }
103
100
 
104
- uint8_t* remaining_source_buffer = source_buffer + source_length;
105
- size_t new_source_length;
101
+ zstds_ext_byte_t* remaining_source_buffer = source_buffer + source_length;
102
+ size_t new_source_length;
106
103
 
107
104
  zstds_ext_result_t ext_result = read_file(source_file, remaining_source_buffer, &new_source_length, remaining_source_buffer_length);
108
105
  if (ext_result != 0) {
@@ -157,8 +154,8 @@ static inline zstds_ext_result_t read_more_source(
157
154
  // Than algorithm can use same buffer again.
158
155
 
159
156
  static inline zstds_ext_result_t flush_destination_buffer(
160
- FILE* destination_file,
161
- uint8_t* destination_buffer, size_t* destination_length_ptr, size_t destination_buffer_length)
157
+ FILE* destination_file,
158
+ zstds_ext_byte_t* destination_buffer, size_t* destination_length_ptr, size_t destination_buffer_length)
162
159
  {
163
160
  if (*destination_length_ptr == 0) {
164
161
  // We want to write more data at once, than buffer has.
@@ -175,7 +172,7 @@ static inline zstds_ext_result_t flush_destination_buffer(
175
172
  return 0;
176
173
  }
177
174
 
178
- static inline zstds_ext_result_t write_remaining_destination(FILE* destination_file, uint8_t* destination_buffer, size_t destination_length)
175
+ static inline zstds_ext_result_t write_remaining_destination(FILE* destination_file, zstds_ext_byte_t* destination_buffer, size_t destination_length)
179
176
  {
180
177
  if (destination_length == 0) {
181
178
  return 0;
@@ -200,9 +197,9 @@ static inline zstds_ext_result_t write_remaining_destination(FILE* destination_f
200
197
  // -- compress --
201
198
 
202
199
  static inline zstds_ext_result_t buffered_compress(
203
- ZSTD_CCtx* ctx,
204
- const uint8_t** source_ptr, size_t* source_length_ptr,
205
- FILE* destination_file, uint8_t* destination_buffer, size_t* destination_length_ptr, size_t destination_buffer_length)
200
+ ZSTD_CCtx* ctx,
201
+ const zstds_ext_byte_t** source_ptr, size_t* source_length_ptr,
202
+ FILE* destination_file, zstds_ext_byte_t* destination_buffer, size_t* destination_length_ptr, size_t destination_buffer_length)
206
203
  {
207
204
  zstds_result_t result;
208
205
  zstds_ext_result_t ext_result;
@@ -249,7 +246,7 @@ static inline zstds_ext_result_t buffered_compress(
249
246
 
250
247
  static inline zstds_ext_result_t buffered_compressor_finish(
251
248
  ZSTD_CCtx* ctx,
252
- FILE* destination_file, uint8_t* destination_buffer, size_t* destination_length_ptr, size_t destination_buffer_length)
249
+ FILE* destination_file, zstds_ext_byte_t* destination_buffer, size_t* destination_length_ptr, size_t destination_buffer_length)
253
250
  {
254
251
  zstds_result_t result;
255
252
  zstds_ext_result_t ext_result;
@@ -293,14 +290,14 @@ static inline zstds_ext_result_t buffered_compressor_finish(
293
290
 
294
291
  static inline zstds_ext_result_t compress(
295
292
  ZSTD_CCtx* ctx,
296
- FILE* source_file, uint8_t* source_buffer, size_t source_buffer_length,
297
- FILE* destination_file, uint8_t* destination_buffer, size_t destination_buffer_length)
293
+ FILE* source_file, zstds_ext_byte_t* source_buffer, size_t source_buffer_length,
294
+ FILE* destination_file, zstds_ext_byte_t* destination_buffer, size_t destination_buffer_length)
298
295
  {
299
296
  zstds_ext_result_t ext_result;
300
297
 
301
- const uint8_t* source = source_buffer;
302
- size_t source_length = 0;
303
- size_t destination_length = 0;
298
+ const zstds_ext_byte_t* source = source_buffer;
299
+ size_t source_length = 0;
300
+ size_t destination_length = 0;
304
301
 
305
302
  BUFFERED_READ_SOURCE(
306
303
  buffered_compress,
@@ -346,8 +343,8 @@ VALUE zstds_ext_compress_io(VALUE ZSTDS_EXT_UNUSED(self), VALUE source, VALUE de
346
343
  destination_buffer_length = ZSTD_CStreamOutSize();
347
344
  }
348
345
 
349
- uint8_t* source_buffer;
350
- uint8_t* destination_buffer;
346
+ zstds_ext_byte_t* source_buffer;
347
+ zstds_ext_byte_t* destination_buffer;
351
348
 
352
349
  ext_result = create_buffers(
353
350
  &source_buffer, source_buffer_length,
@@ -380,9 +377,9 @@ VALUE zstds_ext_compress_io(VALUE ZSTDS_EXT_UNUSED(self), VALUE source, VALUE de
380
377
  // -- decompress --
381
378
 
382
379
  static inline zstds_ext_result_t buffered_decompress(
383
- ZSTD_DCtx* ctx,
384
- const uint8_t** source_ptr, size_t* source_length_ptr,
385
- FILE* destination_file, uint8_t* destination_buffer, size_t* destination_length_ptr, size_t destination_buffer_length)
380
+ ZSTD_DCtx* ctx,
381
+ const zstds_ext_byte_t** source_ptr, size_t* source_length_ptr,
382
+ FILE* destination_file, zstds_ext_byte_t* destination_buffer, size_t* destination_length_ptr, size_t destination_buffer_length)
386
383
  {
387
384
  zstds_result_t result;
388
385
  zstds_ext_result_t ext_result;
@@ -429,14 +426,14 @@ static inline zstds_ext_result_t buffered_decompress(
429
426
 
430
427
  static inline zstds_ext_result_t decompress(
431
428
  ZSTD_DCtx* ctx,
432
- FILE* source_file, uint8_t* source_buffer, size_t source_buffer_length,
433
- FILE* destination_file, uint8_t* destination_buffer, size_t destination_buffer_length)
429
+ FILE* source_file, zstds_ext_byte_t* source_buffer, size_t source_buffer_length,
430
+ FILE* destination_file, zstds_ext_byte_t* destination_buffer, size_t destination_buffer_length)
434
431
  {
435
432
  zstds_ext_result_t ext_result;
436
433
 
437
- const uint8_t* source = source_buffer;
438
- size_t source_length = 0;
439
- size_t destination_length = 0;
434
+ const zstds_ext_byte_t* source = source_buffer;
435
+ size_t source_length = 0;
436
+ size_t destination_length = 0;
440
437
 
441
438
  BUFFERED_READ_SOURCE(
442
439
  buffered_decompress,
@@ -474,8 +471,8 @@ VALUE zstds_ext_decompress_io(VALUE ZSTDS_EXT_UNUSED(self), VALUE source, VALUE
474
471
  destination_buffer_length = ZSTD_DStreamOutSize();
475
472
  }
476
473
 
477
- uint8_t* source_buffer;
478
- uint8_t* destination_buffer;
474
+ zstds_ext_byte_t* source_buffer;
475
+ zstds_ext_byte_t* destination_buffer;
479
476
 
480
477
  ext_result = create_buffers(
481
478
  &source_buffer, source_buffer_length,