lz4rip 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 Lz4rip
4
+ # COVER-based LZ4 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.
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,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.1"
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.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 lz4rip, a pure-Rust LZ4 implementation.
29
+ - - ">="
30
+ - !ruby/object:Gem::Version
31
+ version: 0.9.130
32
+ description: Ruby bindings (via Rust/rb-sys) for lz4rip, a pure-Rust LZ4 implementation.
27
33
  Block-format and frame-format compress/decompress with optional dictionary support
28
34
  and COVER-based dictionary training. Ractor-safe.
29
35
  email:
@@ -39,8 +45,10 @@ files:
39
45
  - LICENSE
40
46
  - README.md
41
47
  - ext/lz4rip/Cargo.toml
48
+ - ext/lz4rip/build.rs
42
49
  - ext/lz4rip/extconf.rb
43
50
  - ext/lz4rip/src/lib.rs
51
+ - ext/lz4rip/src/rb.rs
44
52
  - lib/lz4rip.rb
45
53
  - lib/lz4rip/block_codec.rb
46
54
  - lib/lz4rip/dict_trainer.rb
@@ -52,7 +60,8 @@ licenses:
52
60
  - MIT
53
61
  metadata:
54
62
  homepage_uri: https://github.com/paddor/lz4rip-rb
55
- source_code_uri: https://github.com/paddor/lz4rip-rb
63
+ source_code_uri: https://github.com/paddor/lz4rip-rb/tree/main
64
+ documentation_uri: https://rubydoc.info/gems/lz4rip
56
65
  changelog_uri: https://github.com/paddor/lz4rip-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 LZ4 compression for Ruby
75
84
  test_files: []