zrip 0.1.2 → 0.2.0

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.
@@ -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.0"
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.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Patrik Wenger
@@ -23,7 +23,7 @@ dependencies:
23
23
  - - "~>"
24
24
  - !ruby/object:Gem::Version
25
25
  version: '0.9'
26
- description: Ruby bindings (via Rust/magnus) for zrip, a pure-Rust Zstandard implementation.
26
+ description: Ruby bindings (via Rust/rb-sys) for zrip, a pure-Rust Zstandard implementation.
27
27
  Frame-format and block-format compress/decompress with optional dictionary support,
28
28
  configurable compression levels, and FastCOVER-based dictionary training. Ractor-safe.
29
29
  email:
@@ -39,8 +39,10 @@ files:
39
39
  - LICENSE
40
40
  - README.md
41
41
  - ext/zrip/Cargo.toml
42
+ - ext/zrip/build.rs
42
43
  - ext/zrip/extconf.rb
43
44
  - ext/zrip/src/lib.rs
45
+ - ext/zrip/src/rb.rs
44
46
  - lib/zrip.rb
45
47
  - lib/zrip/block_codec.rb
46
48
  - lib/zrip/dict_trainer.rb
@@ -53,6 +55,7 @@ licenses:
53
55
  metadata:
54
56
  homepage_uri: https://github.com/paddor/zrip-rb
55
57
  source_code_uri: https://github.com/paddor/zrip-rb
58
+ documentation_uri: https://rubydoc.info/gems/zrip
56
59
  changelog_uri: https://github.com/paddor/zrip-rb/blob/main/CHANGELOG.md
57
60
  rubygems_mfa_required: 'true'
58
61
  rdoc_options: []
@@ -62,7 +65,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
62
65
  requirements:
63
66
  - - ">="
64
67
  - !ruby/object:Gem::Version
65
- version: 4.0.0
68
+ version: 3.4.0
66
69
  required_rubygems_version: !ruby/object:Gem::Requirement
67
70
  requirements:
68
71
  - - ">="