Class: Lz4rip::FrameCodec

Inherits:
Object
  • Object
show all
Defined in:
lib/lz4rip/frame_codec.rb

Overview

LZ4 frame-format codec.

FrameCodec is Ractor-shareable.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

._native_new(dict, id) ⇒ FrameCodec

Native constructor used by .new.

Parameters:

  • dict (String, nil)

    dictionary bytes

  • id (Integer)

    dictionary ID, or 0 without a dictionary

Returns:



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/lz4rip/frame_codec.rb', line 48

class FrameCodec
  def self.new(dict: nil)
    case dict
    when nil
      _native_new(nil, 0)
    when Dictionary
      _native_new(dict.bytes, dict.id)
    when String
      _native_new(dict, Dictionary.new(bytes: dict).id)
    else
      raise TypeError, "expected Lz4rip::Dictionary, String, or nil; got #{dict.class}"
    end
  end

  def decompress(bytes, max_decompressed_size: nil)
    _decompress(bytes, max_decompressed_size)
  end
end

.new(dict: nil) ⇒ FrameCodec

Create a frame codec.

Parameters:

  • dict (Dictionary, String, nil) (defaults to: nil)

    optional LZ4 dictionary

Returns:



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/lz4rip/frame_codec.rb', line 48

class FrameCodec
  def self.new(dict: nil)
    case dict
    when nil
      _native_new(nil, 0)
    when Dictionary
      _native_new(dict.bytes, dict.id)
    when String
      _native_new(dict, Dictionary.new(bytes: dict).id)
    else
      raise TypeError, "expected Lz4rip::Dictionary, String, or nil; got #{dict.class}"
    end
  end

  def decompress(bytes, max_decompressed_size: nil)
    _decompress(bytes, max_decompressed_size)
  end
end

Instance Method Details

#_decompress(bytes, max_decompressed_size) ⇒ String

Native decompression entry used by #decompress.

Parameters:

  • bytes (String)

    compressed LZ4 frame

  • max_decompressed_size (Integer, nil)

    optional output byte limit

Returns:

  • (String)

Raises:



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/lz4rip/frame_codec.rb', line 48

class FrameCodec
  def self.new(dict: nil)
    case dict
    when nil
      _native_new(nil, 0)
    when Dictionary
      _native_new(dict.bytes, dict.id)
    when String
      _native_new(dict, Dictionary.new(bytes: dict).id)
    else
      raise TypeError, "expected Lz4rip::Dictionary, String, or nil; got #{dict.class}"
    end
  end

  def decompress(bytes, max_decompressed_size: nil)
    _decompress(bytes, max_decompressed_size)
  end
end

#compress(bytes) ⇒ String

Compress bytes to an LZ4 frame.

Parameters:

  • bytes (String)

    uncompressed bytes

Returns:

  • (String)


48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/lz4rip/frame_codec.rb', line 48

class FrameCodec
  def self.new(dict: nil)
    case dict
    when nil
      _native_new(nil, 0)
    when Dictionary
      _native_new(dict.bytes, dict.id)
    when String
      _native_new(dict, Dictionary.new(bytes: dict).id)
    else
      raise TypeError, "expected Lz4rip::Dictionary, String, or nil; got #{dict.class}"
    end
  end

  def decompress(bytes, max_decompressed_size: nil)
    _decompress(bytes, max_decompressed_size)
  end
end

#decompress(bytes, max_decompressed_size: nil) ⇒ String

Decompress an LZ4 frame.

Parameters:

  • bytes (String)

    compressed LZ4 frame

  • max_decompressed_size (Integer, nil) (defaults to: nil)

    optional output byte limit

Returns:

  • (String)

Raises:



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/lz4rip/frame_codec.rb', line 48

class FrameCodec
  def self.new(dict: nil)
    case dict
    when nil
      _native_new(nil, 0)
    when Dictionary
      _native_new(dict.bytes, dict.id)
    when String
      _native_new(dict, Dictionary.new(bytes: dict).id)
    else
      raise TypeError, "expected Lz4rip::Dictionary, String, or nil; got #{dict.class}"
    end
  end

  def decompress(bytes, max_decompressed_size: nil)
    _decompress(bytes, max_decompressed_size)
  end
end

#has_dict?Boolean

Returns:

  • (Boolean)


48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/lz4rip/frame_codec.rb', line 48

class FrameCodec
  def self.new(dict: nil)
    case dict
    when nil
      _native_new(nil, 0)
    when Dictionary
      _native_new(dict.bytes, dict.id)
    when String
      _native_new(dict, Dictionary.new(bytes: dict).id)
    else
      raise TypeError, "expected Lz4rip::Dictionary, String, or nil; got #{dict.class}"
    end
  end

  def decompress(bytes, max_decompressed_size: nil)
    _decompress(bytes, max_decompressed_size)
  end
end

#idInteger?

Returns dictionary ID.

Returns:

  • (Integer, nil)

    dictionary ID



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/lz4rip/frame_codec.rb', line 48

class FrameCodec
  def self.new(dict: nil)
    case dict
    when nil
      _native_new(nil, 0)
    when Dictionary
      _native_new(dict.bytes, dict.id)
    when String
      _native_new(dict, Dictionary.new(bytes: dict).id)
    else
      raise TypeError, "expected Lz4rip::Dictionary, String, or nil; got #{dict.class}"
    end
  end

  def decompress(bytes, max_decompressed_size: nil)
    _decompress(bytes, max_decompressed_size)
  end
end

#sizeInteger

Returns dictionary size in bytes.

Returns:

  • (Integer)

    dictionary size in bytes



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/lz4rip/frame_codec.rb', line 48

class FrameCodec
  def self.new(dict: nil)
    case dict
    when nil
      _native_new(nil, 0)
    when Dictionary
      _native_new(dict.bytes, dict.id)
    when String
      _native_new(dict, Dictionary.new(bytes: dict).id)
    else
      raise TypeError, "expected Lz4rip::Dictionary, String, or nil; got #{dict.class}"
    end
  end

  def decompress(bytes, max_decompressed_size: nil)
    _decompress(bytes, max_decompressed_size)
  end
end