Class: Zstd::Encoder
- Inherits:
-
Struct
- Object
- Struct
- Zstd::Encoder
- Defined in:
- lib/extzstd.rb
Instance Attribute Summary collapse
-
#destbuf ⇒ Object
Returns the value of attribute destbuf.
-
#encoder ⇒ Object
Returns the value of attribute encoder.
-
#outport ⇒ Object
Returns the value of attribute outport.
-
#status ⇒ Object
Returns the value of attribute status.
Class Method Summary collapse
-
.open(outport, *args) ⇒ Object
call-seq: open(outport, level = nil, dict = nil) -> zstd encoder open(outport, encode_params, dict = nil) { |encoder| … } -> yield returned value.
Instance Method Summary collapse
- #close ⇒ Object
- #eof ⇒ Object (also: #eof?)
- #flush ⇒ Object
-
#initialize(outport, params = nil, dict = nil) ⇒ Encoder
constructor
call-seq: initialize(outport, level = nil, dict = nil) initialize(outport, encode_params, dict = nil).
- #write(buf) ⇒ Object (also: #<<)
Constructor Details
#initialize(outport, params = nil, dict = nil) ⇒ Encoder
call-seq:
initialize(outport, level = nil, dict = nil)
initialize(outport, encode_params, dict = nil)
outport
need has .<< method.
87 88 89 90 |
# File 'lib/extzstd.rb', line 87 def initialize(outport, params = nil, dict = nil) encoder = StreamEncoder.new(params, dict) super encoder, outport, "".force_encoding(Encoding::BINARY), [true] end |
Instance Attribute Details
#destbuf ⇒ Object
Returns the value of attribute destbuf
62 63 64 |
# File 'lib/extzstd.rb', line 62 def destbuf @destbuf end |
#encoder ⇒ Object
Returns the value of attribute encoder
62 63 64 |
# File 'lib/extzstd.rb', line 62 def encoder @encoder end |
#outport ⇒ Object
Returns the value of attribute outport
62 63 64 |
# File 'lib/extzstd.rb', line 62 def outport @outport end |
#status ⇒ Object
Returns the value of attribute status
62 63 64 |
# File 'lib/extzstd.rb', line 62 def status @status end |
Class Method Details
.open(outport, *args) ⇒ Object
call-seq:
open(outport, level = nil, dict = nil) -> zstd encoder
open(outport, encode_params, dict = nil) { |encoder| ... } -> yield returned value
68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/extzstd.rb', line 68 def self.open(outport, *args) e = new(outport, *args) return e unless block_given? begin yield e ensure e.close rescue nil unless e.eof? end end |
Instance Method Details
#close ⇒ Object
98 99 100 101 102 103 104 |
# File 'lib/extzstd.rb', line 98 def close return nil if eof? encoder.end(destbuf, StreamEncoder::OUTSIZE) outport << destbuf status[0] = false nil end |
#eof ⇒ Object Also known as: eof?
92 93 94 |
# File 'lib/extzstd.rb', line 92 def eof !status[0] end |
#flush ⇒ Object
122 123 124 125 126 127 128 129 130 |
# File 'lib/extzstd.rb', line 122 def flush raise IOError, "closed stream" if eof? off = 0 encoder.flush(destbuf, StreamEncoder::OUTSIZE) outport << destbuf self end |
#write(buf) ⇒ Object Also known as: <<
106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/extzstd.rb', line 106 def write(buf) raise IOError, "closed stream" if eof? off = 0 rest = buf.bytesize outsize = StreamEncoder::OUTSIZE while off && off < rest off = encoder.update(buf, off, destbuf, outsize) outport << destbuf end self end |