lz4rip 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,12 +3,22 @@
3
3
  require "digest"
4
4
 
5
5
  module Lz4rip
6
+ # Immutable LZ4 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) do
14
+ # @param bytes [String] dictionary bytes
15
+ # @param id [Integer] optional dictionary ID
7
16
  def initialize(bytes:, id: Digest::SHA256.digest(bytes).byteslice(0, 4).unpack1("V"))
8
17
  super(bytes: bytes.b.freeze, id: id)
9
18
  end
10
19
 
11
20
 
21
+ # @return [Integer] dictionary size in bytes
12
22
  def size
13
23
  bytes.bytesize
14
24
  end
@@ -3,6 +3,48 @@
3
3
  require_relative "dictionary"
4
4
 
5
5
  module Lz4rip
6
+ # LZ4 frame-format codec.
7
+ #
8
+ # `FrameCodec` is Ractor-shareable.
9
+ #
10
+ # @!method self.new(dict: nil)
11
+ # Create a frame codec.
12
+ # @param dict [Dictionary, String, nil] optional LZ4 dictionary
13
+ # @return [FrameCodec]
14
+ #
15
+ # @!method self._native_new(dict, id)
16
+ # Native constructor used by `.new`.
17
+ # @param dict [String, nil] dictionary bytes
18
+ # @param id [Integer] dictionary ID, or `0` without a dictionary
19
+ # @return [FrameCodec]
20
+ #
21
+ # @!method compress(bytes)
22
+ # Compress bytes to an LZ4 frame.
23
+ # @param bytes [String] uncompressed bytes
24
+ # @return [String]
25
+ #
26
+ # @!method decompress(bytes, max_decompressed_size: nil)
27
+ # Decompress an LZ4 frame.
28
+ # @param bytes [String] compressed LZ4 frame
29
+ # @param max_decompressed_size [Integer, nil] optional output byte limit
30
+ # @return [String]
31
+ # @raise [DecompressError]
32
+ #
33
+ # @!method _decompress(bytes, max_decompressed_size)
34
+ # Native decompression entry used by #decompress.
35
+ # @param bytes [String] compressed LZ4 frame
36
+ # @param max_decompressed_size [Integer, nil] optional output byte limit
37
+ # @return [String]
38
+ # @raise [DecompressError]
39
+ #
40
+ # @!method has_dict?
41
+ # @return [Boolean]
42
+ #
43
+ # @!method id
44
+ # @return [Integer, nil] dictionary ID
45
+ #
46
+ # @!method size
47
+ # @return [Integer] dictionary size in bytes
6
48
  class FrameCodec
7
49
  def self.new(dict: nil)
8
50
  case dict
@@ -16,5 +58,9 @@ module Lz4rip
16
58
  raise TypeError, "expected Lz4rip::Dictionary, String, or nil; got #{dict.class}"
17
59
  end
18
60
  end
61
+
62
+ def decompress(bytes, max_decompressed_size: nil)
63
+ _decompress(bytes, max_decompressed_size)
64
+ end
19
65
  end
20
66
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Lz4rip
4
- VERSION = "0.1.2"
4
+ VERSION = "0.2.0"
5
5
  end
data/lib/lz4rip.rb CHANGED
@@ -6,3 +6,20 @@ require_relative "lz4rip/dictionary"
6
6
  require_relative "lz4rip/block_codec"
7
7
  require_relative "lz4rip/frame_codec"
8
8
  require_relative "lz4rip/dict_trainer"
9
+
10
+ # Ractor-safe LZ4 compression for Ruby.
11
+ #
12
+ # @!method self.compress_bound(size)
13
+ # Return the maximum compressed output size for input bytes.
14
+ # @param size [Integer] input size in bytes
15
+ # @return [Integer]
16
+ #
17
+ # @!method self.block_stream_size
18
+ # Return the native block compressor heap size.
19
+ # @return [Integer]
20
+ #
21
+ # @!parse
22
+ # # Raised when LZ4 decompression fails.
23
+ # class DecompressError < StandardError; end
24
+ module Lz4rip
25
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lz4rip
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 lz4rip, a pure-Rust LZ4 implementation.
26
+ description: Ruby bindings (via Rust/rb-sys) for lz4rip, a pure-Rust LZ4 implementation.
27
27
  Block-format and frame-format compress/decompress with optional dictionary support
28
28
  and COVER-based dictionary training. Ractor-safe.
29
29
  email:
@@ -39,8 +39,10 @@ files:
39
39
  - LICENSE
40
40
  - README.md
41
41
  - ext/lz4rip/Cargo.toml
42
+ - ext/lz4rip/build.rs
42
43
  - ext/lz4rip/extconf.rb
43
44
  - ext/lz4rip/src/lib.rs
45
+ - ext/lz4rip/src/rb.rs
44
46
  - lib/lz4rip.rb
45
47
  - lib/lz4rip/block_codec.rb
46
48
  - lib/lz4rip/dict_trainer.rb
@@ -53,6 +55,7 @@ licenses:
53
55
  metadata:
54
56
  homepage_uri: https://github.com/paddor/lz4rip-rb
55
57
  source_code_uri: https://github.com/paddor/lz4rip-rb
58
+ documentation_uri: https://rubydoc.info/gems/lz4rip
56
59
  changelog_uri: https://github.com/paddor/lz4rip-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
  - - ">="