zrip 0.1.2 → 0.2.1

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.
@@ -1,6 +1,38 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Zrip
4
+ # FastCOVER-based Zstandard dictionary trainer.
5
+ #
6
+ # @!method self.new(max_dict_size)
7
+ # Create a dictionary trainer.
8
+ # @param max_dict_size [Integer] maximum dictionary size in bytes
9
+ # @return [DictTrainer]
10
+ #
11
+ # @!method self._native_new(max_dict_size)
12
+ # Native constructor used by `.new`.
13
+ # @param max_dict_size [Integer] maximum dictionary size in bytes
14
+ # @return [DictTrainer]
15
+ #
16
+ # @!method add_sample(bytes)
17
+ # Add a training sample. Samples shorter than 4 bytes are ignored.
18
+ # @param bytes [String] sample bytes
19
+ # @return [nil]
20
+ #
21
+ # @!method train
22
+ # Train and consume the trainer.
23
+ # @return [String] dictionary bytes
24
+ #
25
+ # @!method sample_count
26
+ # @return [Integer] accepted sample count
27
+ #
28
+ # @!method total_bytes
29
+ # @return [Integer] total bytes from accepted samples
30
+ #
31
+ # @!method trained?
32
+ # @return [Boolean]
33
+ #
34
+ # @!method max_dict_size
35
+ # @return [Integer] configured maximum dictionary size
4
36
  class DictTrainer
5
37
  def self.new(max_dict_size)
6
38
  _native_new(max_dict_size)
@@ -3,6 +3,13 @@
3
3
  require "digest"
4
4
 
5
5
  module Zrip
6
+ # Immutable Zstandard dictionary value.
7
+ #
8
+ # @!attribute [r] bytes
9
+ # @return [String] frozen binary dictionary bytes
10
+ #
11
+ # @!attribute [r] id
12
+ # @return [Integer] dictionary ID
6
13
  Dictionary = Data.define(:bytes, :id)
7
14
 
8
15
  class Dictionary
@@ -12,6 +19,8 @@ module Zrip
12
19
  USER_DICT_ID_SIZE = USER_DICT_ID_MAX - USER_DICT_ID_MIN + 1
13
20
 
14
21
 
22
+ # @param bytes [String] dictionary bytes
23
+ # @param id [Integer, nil] optional dictionary ID
15
24
  def initialize(bytes:, id: nil)
16
25
  b = bytes.b
17
26
  id ||= if b.byteslice(0, 4) == ZDICT_MAGIC
@@ -24,6 +33,7 @@ module Zrip
24
33
  end
25
34
 
26
35
 
36
+ # @return [Integer] dictionary size in bytes
27
37
  def size
28
38
  bytes.bytesize
29
39
  end
@@ -3,6 +3,64 @@
3
3
  require_relative "dictionary"
4
4
 
5
5
  module Zrip
6
+ # Zstandard frame-format codec.
7
+ #
8
+ # `FrameCodec` is Ractor-shareable. It uses an internal lock around native
9
+ # compression and decompression contexts.
10
+ #
11
+ # @!method self.new(dict: nil, level: DEFAULT_LEVEL)
12
+ # Create a frame codec.
13
+ # @param dict [Dictionary, String, nil] optional Zstandard dictionary
14
+ # @param level [Integer] compression level
15
+ # @return [FrameCodec]
16
+ #
17
+ # @!method self._native_new(dict, id, level)
18
+ # Native constructor used by `.new`.
19
+ # @param dict [String, nil] dictionary bytes
20
+ # @param id [Integer] dictionary ID, or `0` without a dictionary
21
+ # @param level [Integer] compression level
22
+ # @return [FrameCodec]
23
+ # @raise [CompressError]
24
+ #
25
+ # @!method self.get_frame_content_size(bytes)
26
+ # Read `Frame_Content_Size` from a Zstandard frame header.
27
+ # @param bytes [String] compressed Zstandard frame
28
+ # @return [Integer, nil]
29
+ # @raise [DecompressError]
30
+ #
31
+ # @!method compress(bytes)
32
+ # Compress bytes to a Zstandard frame.
33
+ # @param bytes [String] uncompressed bytes
34
+ # @return [String]
35
+ # @raise [CompressError]
36
+ #
37
+ # @!method decompress(bytes, max_output_size: nil)
38
+ # Decompress a Zstandard frame.
39
+ # @param bytes [String] compressed Zstandard frame
40
+ # @param max_output_size [Integer, nil] optional output byte limit
41
+ # @return [String]
42
+ # @raise [DecompressError]
43
+ # @raise [OutputSizeLimitError]
44
+ #
45
+ # @!method _native_decompress(bytes, max_output_size)
46
+ # Native decompression entry used by #decompress.
47
+ # @param bytes [String] compressed Zstandard frame
48
+ # @param max_output_size [Integer] output byte limit, or `0` for unbounded
49
+ # @return [String]
50
+ # @raise [DecompressError]
51
+ # @raise [OutputSizeLimitError]
52
+ #
53
+ # @!method has_dict?
54
+ # @return [Boolean]
55
+ #
56
+ # @!method id
57
+ # @return [Integer, nil] dictionary ID
58
+ #
59
+ # @!method size
60
+ # @return [Integer] dictionary size in bytes
61
+ #
62
+ # @!method level
63
+ # @return [Integer] compression level
6
64
  class FrameCodec
7
65
  def self.new(dict: nil, level: DEFAULT_LEVEL)
8
66
  case dict
data/lib/zrip/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Zrip
4
- VERSION = "0.1.2"
4
+ VERSION = "0.2.1"
5
5
  end
data/lib/zrip.rb CHANGED
@@ -4,7 +4,21 @@ require_relative "zrip/zrip" # Rust extension
4
4
  require_relative "zrip/version"
5
5
 
6
6
  module Zrip
7
+ # Default compression level used by `FrameCodec` and `BlockCodec`.
7
8
  DEFAULT_LEVEL = 1
9
+
10
+ # @!parse
11
+ # # Raised when Zstandard decompression fails.
12
+ # class DecompressError < StandardError; end
13
+ #
14
+ # # Raised when Zstandard compression fails.
15
+ # class CompressError < StandardError; end
16
+ #
17
+ # # Reserved subclass for streams without a declared frame content size.
18
+ # class MissingContentSizeError < DecompressError; end
19
+ #
20
+ # # Raised when decompressed output exceeds the requested limit.
21
+ # class OutputSizeLimitError < DecompressError; end
8
22
  end
9
23
 
10
24
  require_relative "zrip/dictionary"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zrip
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Patrik Wenger
@@ -16,6 +16,9 @@ dependencies:
16
16
  - - "~>"
17
17
  - !ruby/object:Gem::Version
18
18
  version: '0.9'
19
+ - - ">="
20
+ - !ruby/object:Gem::Version
21
+ version: 0.9.130
19
22
  type: :runtime
20
23
  prerelease: false
21
24
  version_requirements: !ruby/object:Gem::Requirement
@@ -23,7 +26,10 @@ dependencies:
23
26
  - - "~>"
24
27
  - !ruby/object:Gem::Version
25
28
  version: '0.9'
26
- description: Ruby bindings (via Rust/magnus) for zrip, a pure-Rust Zstandard implementation.
29
+ - - ">="
30
+ - !ruby/object:Gem::Version
31
+ version: 0.9.130
32
+ description: Ruby bindings (via Rust/rb-sys) for zrip, a pure-Rust Zstandard implementation.
27
33
  Frame-format and block-format compress/decompress with optional dictionary support,
28
34
  configurable compression levels, and FastCOVER-based dictionary training. Ractor-safe.
29
35
  email:
@@ -39,8 +45,10 @@ files:
39
45
  - LICENSE
40
46
  - README.md
41
47
  - ext/zrip/Cargo.toml
48
+ - ext/zrip/build.rs
42
49
  - ext/zrip/extconf.rb
43
50
  - ext/zrip/src/lib.rs
51
+ - ext/zrip/src/rb.rs
44
52
  - lib/zrip.rb
45
53
  - lib/zrip/block_codec.rb
46
54
  - lib/zrip/dict_trainer.rb
@@ -52,7 +60,8 @@ licenses:
52
60
  - MIT
53
61
  metadata:
54
62
  homepage_uri: https://github.com/paddor/zrip-rb
55
- source_code_uri: https://github.com/paddor/zrip-rb
63
+ source_code_uri: https://github.com/paddor/zrip-rb/tree/main
64
+ documentation_uri: https://rubydoc.info/gems/zrip
56
65
  changelog_uri: https://github.com/paddor/zrip-rb/blob/main/CHANGELOG.md
57
66
  rubygems_mfa_required: 'true'
58
67
  rdoc_options: []
@@ -62,14 +71,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
62
71
  requirements:
63
72
  - - ">="
64
73
  - !ruby/object:Gem::Version
65
- version: 4.0.0
74
+ version: 3.4.0
66
75
  required_rubygems_version: !ruby/object:Gem::Requirement
67
76
  requirements:
68
77
  - - ">="
69
78
  - !ruby/object:Gem::Version
70
79
  version: '0'
71
80
  requirements: []
72
- rubygems_version: 4.0.16
81
+ rubygems_version: 4.0.20
73
82
  specification_version: 4
74
83
  summary: Ractor-safe Zstandard bindings for Ruby (pure-Rust zrip backend)
75
84
  test_files: []