ruby-xz 0.2.2 → 1.0.2
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.
- checksums.yaml +5 -5
- data/AUTHORS +3 -4
- data/HISTORY.rdoc +66 -6
- data/LICENSE +21 -0
- data/README.md +99 -77
- data/lib/xz/fiddle_helper.rb +91 -0
- data/lib/xz/lib_lzma.rb +117 -103
- data/lib/xz/stream.rb +429 -32
- data/lib/xz/stream_reader.rb +221 -400
- data/lib/xz/stream_writer.rb +173 -314
- data/lib/xz/version.rb +5 -6
- data/lib/xz.rb +172 -98
- metadata +35 -27
- data/COPYING +0 -26
data/lib/xz.rb
CHANGED
@@ -1,11 +1,10 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
#--
|
3
|
-
# (The MIT License)
|
4
|
-
#
|
5
3
|
# Basic liblzma-bindings for Ruby.
|
6
4
|
#
|
7
|
-
# Copyright © 2011
|
8
|
-
#
|
5
|
+
# Copyright © 2011-2018 Marvin Gülker et al.
|
6
|
+
#
|
7
|
+
# See AUTHORS for the full list of contributors.
|
9
8
|
#
|
10
9
|
# Permission is hereby granted, free of charge, to any person obtaining a
|
11
10
|
# copy of this software and associated documentation files (the ‘Software’),
|
@@ -27,20 +26,14 @@
|
|
27
26
|
#++
|
28
27
|
|
29
28
|
require "pathname"
|
30
|
-
require "
|
31
|
-
require
|
32
|
-
require "
|
29
|
+
require "fiddle"
|
30
|
+
require "fiddle/import"
|
31
|
+
require "stringio"
|
32
|
+
require "forwardable"
|
33
33
|
|
34
34
|
# The namespace and main module of this library. Each method of this
|
35
35
|
# module may raise exceptions of class XZ::LZMAError, which is not
|
36
36
|
# named in the methods' documentations anymore.
|
37
|
-
#
|
38
|
-
# All strings you receive from any method defined in this module and
|
39
|
-
# the classes defined in it are encoded in BINARY, so you may have to
|
40
|
-
# call #force_encoding on them to tag them with the correct encoding
|
41
|
-
# (assuming you _know_ what their correct encoding should be).
|
42
|
-
# ruby-xz can’t handle this as compiled strings don’t come with
|
43
|
-
# encoding information.
|
44
37
|
module XZ
|
45
38
|
|
46
39
|
# Number of bytes read in one chunk.
|
@@ -48,17 +41,6 @@ module XZ
|
|
48
41
|
|
49
42
|
class << self
|
50
43
|
|
51
|
-
# :nodoc:
|
52
|
-
#
|
53
|
-
# Output a deprecation notice.
|
54
|
-
def deprecate(msg)
|
55
|
-
@disable_deprecation_notices ||= false
|
56
|
-
|
57
|
-
unless @disable_deprecation_notices
|
58
|
-
$stderr.puts("DEPRECATION NOTICE: #{msg}\n#{caller.drop(1).join("\n\t")}")
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
44
|
# Force ruby-xz to be silent about deprecations. Using this is
|
63
45
|
# discouraged so that you are aware of upcoming changes to the
|
64
46
|
# API. However, if your standard error stream is closed,
|
@@ -69,18 +51,34 @@ module XZ
|
|
69
51
|
@disable_deprecation_notices = bool
|
70
52
|
end
|
71
53
|
|
54
|
+
# Output a deprecation notice.
|
55
|
+
def deprecate(msg) # :nodoc:
|
56
|
+
@disable_deprecation_notices ||= false
|
57
|
+
|
58
|
+
unless @disable_deprecation_notices
|
59
|
+
$stderr.puts("DEPRECATION NOTICE: #{msg}\n#{caller.drop(1).join("\n\t")}")
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
72
63
|
# call-seq:
|
73
|
-
# decompress_stream(io [,
|
74
|
-
# decompress_stream(io [,
|
75
|
-
# decode_stream(io [,
|
76
|
-
# decode_stream(io [,
|
64
|
+
# decompress_stream(io [, kw ] ) → a_string
|
65
|
+
# decompress_stream(io [, kw ] ] ){|chunk| ... } → an_integer
|
66
|
+
# decode_stream(io [, kw ] ] ) → a_string
|
67
|
+
# decode_stream(io [, kw ] ){|chunk| ... } → an_integer
|
77
68
|
#
|
78
69
|
# Decompresses a stream containing XZ-compressed data.
|
79
70
|
#
|
80
71
|
# === Parameters
|
72
|
+
# ==== Positional parameters
|
81
73
|
#
|
82
74
|
# [io]
|
83
|
-
# The IO to read from. It must be opened for reading
|
75
|
+
# The IO to read from. It must be opened for reading in
|
76
|
+
# binary mode.
|
77
|
+
# [chunk (Block argument)]
|
78
|
+
# One piece of decompressed data. See Remarks section below
|
79
|
+
# for information about its encoding.
|
80
|
+
#
|
81
|
+
# ==== Keyword arguments
|
84
82
|
#
|
85
83
|
# [memory_limit (+UINT64_MAX+)]
|
86
84
|
# If not XZ::LibLZMA::UINT64_MAX, makes liblzma
|
@@ -98,9 +96,13 @@ module XZ
|
|
98
96
|
# has an unsupported checksum type.
|
99
97
|
# [:concatenated]
|
100
98
|
# Decompress concatenated archives.
|
101
|
-
#
|
102
|
-
#
|
103
|
-
#
|
99
|
+
# [external_encoding (Encoding.default_external)]
|
100
|
+
# Assume the decompressed data inside the compressed data
|
101
|
+
# has this encoding. See Remarks section.
|
102
|
+
# [internal_encoding (Encoding.default_internal)]
|
103
|
+
# Request transcoding of the decompressed data into this
|
104
|
+
# encoding if not nil. Note that Encoding.default_internal
|
105
|
+
# is nil by default. See Remarks section.
|
104
106
|
#
|
105
107
|
# === Return value
|
106
108
|
#
|
@@ -108,6 +110,18 @@ module XZ
|
|
108
110
|
# written. Otherwise, returns the decompressed data as a
|
109
111
|
# BINARY-encoded string.
|
110
112
|
#
|
113
|
+
# === Raises
|
114
|
+
#
|
115
|
+
# [Encoding::InvalidByteSequenceError]
|
116
|
+
# 1. You requested an “internal encoding” conversion
|
117
|
+
# and the archive contains invalid byte sequences
|
118
|
+
# in the external encoding.
|
119
|
+
# 2. You requested an “internal encoding” conversion, used
|
120
|
+
# the block form of this method, and liblzma decided
|
121
|
+
# to cut the decompressed data into chunks in mid of
|
122
|
+
# a multibyte character. See Remarks section for an
|
123
|
+
# explanation.
|
124
|
+
#
|
111
125
|
# === Example
|
112
126
|
#
|
113
127
|
# data = File.open("archive.xz", "rb"){|f| f.read}
|
@@ -127,8 +141,52 @@ module XZ
|
|
127
141
|
# know how big your data gets or if you want to decompress much
|
128
142
|
# data, use the block form. Of course you shouldn't store the data
|
129
143
|
# you read in RAM then as in the example above.
|
130
|
-
|
144
|
+
#
|
145
|
+
# This method honours Ruby's external and internal encoding concept.
|
146
|
+
# All documentation about this applies to this method, with the
|
147
|
+
# exception that the external encoding does not refer to the data
|
148
|
+
# on the hard disk (that's compressed XZ data, it's always binary),
|
149
|
+
# but to the data inside the XZ container, i.e. to the *decompressed*
|
150
|
+
# data. Any strings you receive from this method (regardless of
|
151
|
+
# whether via return value or via the +chunk+ block argument) will
|
152
|
+
# first be tagged with the external encoding. If you set an internal
|
153
|
+
# encoding (either via the +internal_encoding+ parameter or via
|
154
|
+
# Ruby's default internal encoding) that string will be transcoded
|
155
|
+
# from the external encoding to the internal encoding before you
|
156
|
+
# even see it; in that case, the return value or chunk block argument
|
157
|
+
# will be encoded in the internal encoding. Internal encoding is
|
158
|
+
# disabled in Ruby by default and the argument for this method also
|
159
|
+
# defaults to nil.
|
160
|
+
#
|
161
|
+
# Due to the external encoding being applied, it can happen that
|
162
|
+
# +chunk+ contains an incomplete multibyte character causing
|
163
|
+
# <tt>valid_encoding?</tt> to return false if called on +chunk+,
|
164
|
+
# because liblzma doesn't know about encodings. The rest of the
|
165
|
+
# character will be yielded to the block in the next iteration
|
166
|
+
# then as liblzma progresses with the decompression from the XZ
|
167
|
+
# format. In other words, be prepared that +chunk+ can contain
|
168
|
+
# incomplete multibyte chars.
|
169
|
+
#
|
170
|
+
# This can have nasty side effects if you requested an internal
|
171
|
+
# encoding automatic transcoding and used the block form. Since
|
172
|
+
# this method applies the internal encoding transcoding before the
|
173
|
+
# chunk is yielded to the block, String#encode gets the incomplete
|
174
|
+
# multibyte character. In that case, you will receive an
|
175
|
+
# Encoding::InvalidByteSequenceError exception even though your
|
176
|
+
# data is perfectly well-formed inside the XZ data. It's just
|
177
|
+
# that liblzma during decompression cut the chunks at an
|
178
|
+
# unfortunate place. To avoid this, do not request internal encoding
|
179
|
+
# conversion when using the block form, but instead transcode
|
180
|
+
# the data manually after you have decompressed the entire data.
|
181
|
+
def decompress_stream(io, memory_limit: LibLZMA::UINT64_MAX, flags: [:tell_unsupported_check], external_encoding: nil, internal_encoding: nil, &block)
|
131
182
|
raise(ArgumentError, "Invalid memory limit set!") unless memory_limit > 0 && memory_limit <= LibLZMA::UINT64_MAX
|
183
|
+
raise(ArgumentError, "external_encoding must be set if internal_encoding transcoding is requested") if internal_encoding && !external_encoding
|
184
|
+
|
185
|
+
# The ArgumentError above is only about the concrete arguments
|
186
|
+
# (to sync with Ruby's IO API), not about the implied internal
|
187
|
+
# encoding, which might still kick in (and does, see below).
|
188
|
+
external_encoding ||= Encoding.default_external
|
189
|
+
internal_encoding ||= Encoding.default_internal
|
132
190
|
|
133
191
|
# bit-or all flags
|
134
192
|
allflags = flags.inject(0) do |val, flag|
|
@@ -136,8 +194,9 @@ module XZ
|
|
136
194
|
val | flag
|
137
195
|
end
|
138
196
|
|
139
|
-
stream = LZMAStream.
|
140
|
-
|
197
|
+
stream = LibLZMA::LZMAStream.malloc
|
198
|
+
LibLZMA.LZMA_STREAM_INIT(stream)
|
199
|
+
res = LibLZMA.lzma_stream_decoder(stream.to_ptr,
|
141
200
|
memory_limit,
|
142
201
|
allflags)
|
143
202
|
|
@@ -146,32 +205,46 @@ module XZ
|
|
146
205
|
res = ""
|
147
206
|
res.encode!(Encoding::BINARY)
|
148
207
|
if block_given?
|
149
|
-
res = lzma_code(io, stream
|
208
|
+
res = lzma_code(io, stream) do |chunk|
|
209
|
+
chunk = chunk.dup # Do not write somewhere into the fiddle pointer while encoding (-> can segfault)
|
210
|
+
chunk.force_encoding(external_encoding) if external_encoding
|
211
|
+
chunk.encode!(internal_encoding) if internal_encoding
|
212
|
+
yield(chunk)
|
213
|
+
end
|
150
214
|
else
|
151
215
|
lzma_code(io, stream){|chunk| res << chunk}
|
216
|
+
res.force_encoding(external_encoding) if external_encoding
|
217
|
+
res.encode!(internal_encoding) if internal_encoding
|
152
218
|
end
|
153
219
|
|
154
|
-
LibLZMA.lzma_end(stream.
|
220
|
+
LibLZMA.lzma_end(stream.to_ptr)
|
155
221
|
|
156
|
-
block_given? ? stream
|
222
|
+
block_given? ? stream.total_out : res
|
157
223
|
end
|
158
224
|
alias decode_stream decompress_stream
|
159
225
|
|
160
226
|
# call-seq:
|
161
|
-
# compress_stream(io [,
|
162
|
-
# compress_stream(io [,
|
163
|
-
# encode_stream(io [,
|
164
|
-
# encode_stream(io [,
|
227
|
+
# compress_stream(io [, kw ] ) → a_string
|
228
|
+
# compress_stream(io [, kw ] ){|chunk| ... } → an_integer
|
229
|
+
# encode_stream(io [, kw ] ) → a_string
|
230
|
+
# encode_stream(io [, kw ] ){|chunk| ... } → an_integer
|
165
231
|
#
|
166
232
|
# Compresses a stream of data into XZ-compressed data.
|
167
233
|
#
|
168
234
|
# === Parameters
|
235
|
+
# ==== Positional arguments
|
169
236
|
#
|
170
237
|
# [io]
|
171
238
|
# The IO to read the data from. Must be opened for
|
172
239
|
# reading.
|
240
|
+
# [chunk (Block argument)]
|
241
|
+
# One piece of compressed data. This is always tagged
|
242
|
+
# as a BINARY string, since it's compressed binary data.
|
243
|
+
#
|
244
|
+
# ==== Keyword arguments
|
245
|
+
# All keyword arguments are optional.
|
173
246
|
#
|
174
|
-
# [
|
247
|
+
# [level (6)]
|
175
248
|
# Compression strength. Higher values indicate a
|
176
249
|
# smaller result, but longer compression time. Maximum
|
177
250
|
# is 9.
|
@@ -189,9 +262,6 @@ module XZ
|
|
189
262
|
# compression. This may succeed, but you can end
|
190
263
|
# up with *very* long computation times.
|
191
264
|
#
|
192
|
-
# [chunk (Block argument)]
|
193
|
-
# One piece of compressed data.
|
194
|
-
#
|
195
265
|
# === Return value
|
196
266
|
#
|
197
267
|
# If a block was given, returns the number of bytes
|
@@ -206,7 +276,9 @@ module XZ
|
|
206
276
|
# i.rewind
|
207
277
|
# str = ""
|
208
278
|
#
|
209
|
-
# XZ.compress_stream(i, 4, :sha256)
|
279
|
+
# XZ.compress_stream(i, level: 4, check: :sha256) do |c|
|
280
|
+
# str << c
|
281
|
+
# end #=> 123
|
210
282
|
# str #=> Some binary blob
|
211
283
|
#
|
212
284
|
# === Remarks
|
@@ -216,16 +288,23 @@ module XZ
|
|
216
288
|
# know how big your data gets or if you want to compress much
|
217
289
|
# data, use the block form. Of course you shouldn't store the data
|
218
290
|
# your read in RAM then as in the example above.
|
219
|
-
|
220
|
-
|
291
|
+
#
|
292
|
+
# For the +io+ object passed Ruby's normal external and internal
|
293
|
+
# encoding rules apply while it is read from by this method. These
|
294
|
+
# encodings are not changed on +io+ by this method. The data you
|
295
|
+
# receive in the block (+chunk+) above is binary data (compressed
|
296
|
+
# data) and as such encoded as BINARY.
|
297
|
+
def compress_stream(io, level: 6, check: :crc64, extreme: false, &block)
|
298
|
+
raise(ArgumentError, "Invalid compression level!") unless (0..9).include?(level)
|
221
299
|
raise(ArgumentError, "Invalid checksum specified!") unless [:none, :crc32, :crc64, :sha256].include?(check)
|
222
300
|
|
223
|
-
|
301
|
+
level |= LibLZMA::LZMA_PRESET_EXTREME if extreme
|
224
302
|
|
225
|
-
stream = LZMAStream.
|
226
|
-
|
227
|
-
|
228
|
-
|
303
|
+
stream = LibLZMA::LZMAStream.malloc
|
304
|
+
LibLZMA::LZMA_STREAM_INIT(stream)
|
305
|
+
res = LibLZMA.lzma_easy_encoder(stream.to_ptr,
|
306
|
+
level,
|
307
|
+
LibLZMA.const_get(:"LZMA_CHECK_#{check.upcase}"))
|
229
308
|
|
230
309
|
LZMAError.raise_if_necessary(res)
|
231
310
|
|
@@ -237,9 +316,9 @@ module XZ
|
|
237
316
|
lzma_code(io, stream){|chunk| res << chunk}
|
238
317
|
end
|
239
318
|
|
240
|
-
LibLZMA.lzma_end(stream.
|
319
|
+
LibLZMA.lzma_end(stream.to_ptr)
|
241
320
|
|
242
|
-
block_given? ? stream
|
321
|
+
block_given? ? stream.total_out : res
|
243
322
|
end
|
244
323
|
alias encode_stream compress_stream
|
245
324
|
|
@@ -253,7 +332,7 @@ module XZ
|
|
253
332
|
# The path of the file to write to. If it exists, it will be
|
254
333
|
# overwritten.
|
255
334
|
#
|
256
|
-
# For the
|
335
|
+
# For the keyword parameters, see the ::compress_stream method.
|
257
336
|
#
|
258
337
|
# === Return value
|
259
338
|
#
|
@@ -261,17 +340,17 @@ module XZ
|
|
261
340
|
#
|
262
341
|
# === Example
|
263
342
|
#
|
264
|
-
# XZ.
|
265
|
-
# XZ.
|
343
|
+
# XZ.compress_file("myfile.txt", "myfile.txt.xz")
|
344
|
+
# XZ.compress_file("myarchive.tar", "myarchive.tar.xz")
|
266
345
|
#
|
267
346
|
# === Remarks
|
268
347
|
#
|
269
348
|
# This method is safe to use with big files, because files are not
|
270
349
|
# loaded into memory completely at once.
|
271
|
-
def compress_file(in_file, out_file,
|
350
|
+
def compress_file(in_file, out_file, **args)
|
272
351
|
File.open(in_file, "rb") do |i_file|
|
273
352
|
File.open(out_file, "wb") do |o_file|
|
274
|
-
compress_stream(i_file,
|
353
|
+
compress_stream(i_file, **args) do |chunk|
|
275
354
|
o_file.write(chunk)
|
276
355
|
end
|
277
356
|
end
|
@@ -284,7 +363,7 @@ module XZ
|
|
284
363
|
#
|
285
364
|
# [str] The data to compress.
|
286
365
|
#
|
287
|
-
# For the
|
366
|
+
# For the keyword parameters, see the #compress_stream method.
|
288
367
|
#
|
289
368
|
# === Return value
|
290
369
|
#
|
@@ -299,10 +378,9 @@ module XZ
|
|
299
378
|
#
|
300
379
|
# Don't use this method for big amounts of data--you may run out
|
301
380
|
# of memory. Use compress_file or compress_stream instead.
|
302
|
-
def compress(str,
|
303
|
-
raise(NotImplementedError, "StringIO isn't available!") unless defined? StringIO
|
381
|
+
def compress(str, **args)
|
304
382
|
s = StringIO.new(str)
|
305
|
-
compress_stream(s,
|
383
|
+
compress_stream(s, **args)
|
306
384
|
end
|
307
385
|
|
308
386
|
# Decompresses data in XZ format.
|
@@ -311,7 +389,7 @@ module XZ
|
|
311
389
|
#
|
312
390
|
# [str] The data to decompress.
|
313
391
|
#
|
314
|
-
# For the
|
392
|
+
# For the keyword parameters, see the decompress_stream method.
|
315
393
|
#
|
316
394
|
# === Return value
|
317
395
|
#
|
@@ -326,10 +404,12 @@ module XZ
|
|
326
404
|
#
|
327
405
|
# Don't use this method for big amounts of data--you may run out
|
328
406
|
# of memory. Use decompress_file or decompress_stream instead.
|
329
|
-
|
330
|
-
|
407
|
+
#
|
408
|
+
# Read #decompress_stream's Remarks section for notes on the
|
409
|
+
# return value's encoding.
|
410
|
+
def decompress(str, **args)
|
331
411
|
s = StringIO.new(str)
|
332
|
-
decompress_stream(s,
|
412
|
+
decompress_stream(s, **args)
|
333
413
|
end
|
334
414
|
|
335
415
|
# Decompresses +in_file+ and writes the result to +out_file+.
|
@@ -342,7 +422,7 @@ module XZ
|
|
342
422
|
# The path of the file to write to. If it exists, it will
|
343
423
|
# be overwritten.
|
344
424
|
#
|
345
|
-
# For the
|
425
|
+
# For the keyword parameters, see the decompress_stream method.
|
346
426
|
#
|
347
427
|
# === Return value
|
348
428
|
#
|
@@ -351,17 +431,17 @@ module XZ
|
|
351
431
|
#
|
352
432
|
# === Example
|
353
433
|
#
|
354
|
-
# XZ.
|
355
|
-
# XZ.
|
434
|
+
# XZ.decompress_file("myfile.txt.xz", "myfile.txt")
|
435
|
+
# XZ.decompress_file("myarchive.tar.xz", "myarchive.tar")
|
356
436
|
#
|
357
437
|
# === Remarks
|
358
438
|
#
|
359
439
|
# This method is safe to use with big files, because files are not
|
360
440
|
# loaded into memory completely at once.
|
361
|
-
def decompress_file(in_file, out_file,
|
441
|
+
def decompress_file(in_file, out_file, **args)
|
362
442
|
File.open(in_file, "rb") do |i_file|
|
363
443
|
File.open(out_file, "wb") do |o_file|
|
364
|
-
decompress_stream(i_file,
|
444
|
+
decompress_stream(i_file, internal_encoding: nil, external_encoding: Encoding::BINARY, **args) do |chunk|
|
365
445
|
o_file.write(chunk)
|
366
446
|
end
|
367
447
|
end
|
@@ -370,30 +450,23 @@ module XZ
|
|
370
450
|
|
371
451
|
private
|
372
452
|
|
373
|
-
# This method returns the size of +str+ in bytes.
|
374
|
-
def binary_size(str)
|
375
|
-
# Believe it or not, but this is faster than str.bytes.to_a.size.
|
376
|
-
# I benchmarked it, and it is as twice as fast.
|
377
|
-
str.dup.force_encoding(Encoding::BINARY).size
|
378
|
-
end
|
379
|
-
|
380
453
|
# This method does the heavy work of (de-)compressing a stream. It
|
381
454
|
# takes an IO object to read data from (that means the IO must be
|
382
|
-
# opened for reading) and a XZ::LZMAStream object that is used to
|
455
|
+
# opened for reading) and a XZ::LibLZMA::LZMAStream object that is used to
|
383
456
|
# (de-)compress the data. Furthermore this method takes a block
|
384
457
|
# which gets passed the (de-)compressed data in chunks one at a
|
385
458
|
# time--this is needed to allow (de-)compressing of very large
|
386
459
|
# files that can't be loaded fully into memory.
|
387
460
|
def lzma_code(io, stream)
|
388
|
-
input_buffer_p =
|
389
|
-
output_buffer_p =
|
461
|
+
input_buffer_p = Fiddle::Pointer.malloc(CHUNK_SIZE) # automatically freed by fiddle on GC
|
462
|
+
output_buffer_p = Fiddle::Pointer.malloc(CHUNK_SIZE) # automatically freed by fiddle on GC
|
390
463
|
|
391
464
|
while str = io.read(CHUNK_SIZE)
|
392
|
-
input_buffer_p.
|
465
|
+
input_buffer_p[0, str.bytesize] = str
|
393
466
|
|
394
467
|
# Set the data for compressing
|
395
|
-
stream
|
396
|
-
stream
|
468
|
+
stream.next_in = input_buffer_p
|
469
|
+
stream.avail_in = str.bytesize
|
397
470
|
|
398
471
|
# Now loop until we gathered all the data in
|
399
472
|
# stream[:next_out]. Depending on the amount of data, this may
|
@@ -407,25 +480,26 @@ module XZ
|
|
407
480
|
# the amount of data to compress is small).
|
408
481
|
loop do
|
409
482
|
# Prepare for getting the compressed_data
|
410
|
-
stream
|
411
|
-
stream
|
483
|
+
stream.next_out = output_buffer_p
|
484
|
+
stream.avail_out = CHUNK_SIZE
|
412
485
|
|
413
486
|
# Compress the data
|
414
487
|
res = if io.eof?
|
415
|
-
LibLZMA.lzma_code(stream.
|
488
|
+
LibLZMA.lzma_code(stream.to_ptr, LibLZMA::LZMA_FINISH)
|
416
489
|
else
|
417
|
-
LibLZMA.lzma_code(stream.
|
490
|
+
LibLZMA.lzma_code(stream.to_ptr, LibLZMA::LZMA_RUN)
|
418
491
|
end
|
419
492
|
check_lzma_code_retval(res)
|
420
493
|
|
421
494
|
# Write the compressed data
|
422
|
-
|
495
|
+
# Note: avail_out gives how much space is left after the new data
|
496
|
+
data = output_buffer_p[0, CHUNK_SIZE - stream.avail_out]
|
423
497
|
yield(data)
|
424
498
|
|
425
499
|
# If the buffer is completely filled, it's likely that there
|
426
500
|
# is more data liblzma wants to hand to us. Start a new
|
427
501
|
# iteration, but don't provide new input data.
|
428
|
-
break unless stream
|
502
|
+
break unless stream.avail_out == 0
|
429
503
|
end #loop
|
430
504
|
end #while
|
431
505
|
end #lzma_code
|
@@ -434,11 +508,10 @@ module XZ
|
|
434
508
|
# return value of the lzma_code() function and shows them if
|
435
509
|
# necessary.
|
436
510
|
def check_lzma_code_retval(code)
|
437
|
-
e = LibLZMA::LZMA_RET
|
438
511
|
case code
|
439
|
-
when
|
440
|
-
when
|
441
|
-
when
|
512
|
+
when LibLZMA::LZMA_NO_CHECK then warn("Couldn't verify archive integrity--archive has no integrity checksum.")
|
513
|
+
when LibLZMA::LZMA_UNSUPPORTED_CHECK then warn("Couldn't verify archive integrity--archive has an unsupported integrity checksum.")
|
514
|
+
when LibLZMA::LZMA_GET_CHECK then nil # This isn't useful. It indicates that the checksum type is now known.
|
442
515
|
else
|
443
516
|
LZMAError.raise_if_necessary(code)
|
444
517
|
end
|
@@ -449,6 +522,7 @@ module XZ
|
|
449
522
|
end
|
450
523
|
|
451
524
|
require_relative "xz/version"
|
525
|
+
require_relative "xz/fiddle_helper"
|
452
526
|
require_relative "xz/lib_lzma"
|
453
527
|
require_relative "xz/stream"
|
454
528
|
require_relative "xz/stream_writer"
|
metadata
CHANGED
@@ -1,87 +1,96 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-xz
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marvin Gülker
|
8
|
-
|
8
|
+
- Alex Gittemeier
|
9
|
+
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date:
|
12
|
+
date: 2021-11-29 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
15
|
+
name: minitar
|
15
16
|
requirement: !ruby/object:Gem::Requirement
|
16
17
|
requirements:
|
17
18
|
- - "~>"
|
18
19
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
20
|
-
type: :
|
20
|
+
version: '0.6'
|
21
|
+
type: :development
|
21
22
|
prerelease: false
|
22
23
|
version_requirements: !ruby/object:Gem::Requirement
|
23
24
|
requirements:
|
24
25
|
- - "~>"
|
25
26
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
27
|
+
version: '0.6'
|
27
28
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
29
|
+
name: minitest
|
29
30
|
requirement: !ruby/object:Gem::Requirement
|
30
31
|
requirements:
|
31
32
|
- - "~>"
|
32
33
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
34
|
-
type: :
|
34
|
+
version: '5.14'
|
35
|
+
type: :development
|
35
36
|
prerelease: false
|
36
37
|
version_requirements: !ruby/object:Gem::Requirement
|
37
38
|
requirements:
|
38
39
|
- - "~>"
|
39
40
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
41
|
+
version: '5.14'
|
41
42
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
43
|
+
name: rake
|
43
44
|
requirement: !ruby/object:Gem::Requirement
|
44
45
|
requirements:
|
45
46
|
- - "~>"
|
46
47
|
- !ruby/object:Gem::Version
|
47
|
-
version: '0
|
48
|
+
version: '13.0'
|
48
49
|
type: :development
|
49
50
|
prerelease: false
|
50
51
|
version_requirements: !ruby/object:Gem::Requirement
|
51
52
|
requirements:
|
52
53
|
- - "~>"
|
53
54
|
- !ruby/object:Gem::Version
|
54
|
-
version: '0
|
55
|
+
version: '13.0'
|
55
56
|
description: |
|
56
57
|
These are simple Ruby bindings for the liblzma library
|
57
58
|
(http://tukaani.org/xz/), which is best known for the
|
58
59
|
extreme compression ratio its native XZ format achieves.
|
59
|
-
Since
|
60
|
-
is needed
|
61
|
-
email:
|
60
|
+
Since fiddle is used to implement the bindings, no compilation
|
61
|
+
is needed.
|
62
|
+
email: me@a.lexg.dev
|
62
63
|
executables: []
|
63
64
|
extensions: []
|
64
65
|
extra_rdoc_files:
|
65
66
|
- README.md
|
66
67
|
- HISTORY.rdoc
|
67
|
-
-
|
68
|
+
- LICENSE
|
68
69
|
- AUTHORS
|
69
70
|
files:
|
70
71
|
- AUTHORS
|
71
|
-
- COPYING
|
72
72
|
- HISTORY.rdoc
|
73
|
+
- LICENSE
|
73
74
|
- README.md
|
74
75
|
- lib/xz.rb
|
76
|
+
- lib/xz/fiddle_helper.rb
|
75
77
|
- lib/xz/lib_lzma.rb
|
76
78
|
- lib/xz/stream.rb
|
77
79
|
- lib/xz/stream_reader.rb
|
78
80
|
- lib/xz/stream_writer.rb
|
79
81
|
- lib/xz/version.rb
|
80
|
-
homepage:
|
82
|
+
homepage: https://github.com/win93/ruby-xz
|
81
83
|
licenses:
|
82
84
|
- MIT
|
83
|
-
metadata:
|
84
|
-
|
85
|
+
metadata:
|
86
|
+
homepage_uri: https://github.com/win93/ruby-xz
|
87
|
+
source_code_uri: https://github.com/win93/ruby-xz/tree/stable
|
88
|
+
documentation_uri: https://www.rubydoc.info/gems/ruby-xz
|
89
|
+
bug_tracker_uri: https://github.com/win93/ruby-xz/issues
|
90
|
+
changelog_uri: https://github.com/win93/ruby-xz/blob/stable/HISTORY.rdoc
|
91
|
+
rubygems_mfa_required: 'true'
|
92
|
+
post_install_message: Version 1.0.0 of ruby-xz breaks the API. Read HISTORY.rdoc and
|
93
|
+
adapt your code to the new API.
|
85
94
|
rdoc_options:
|
86
95
|
- "-t"
|
87
96
|
- ruby-xz RDocs
|
@@ -93,16 +102,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
93
102
|
requirements:
|
94
103
|
- - ">="
|
95
104
|
- !ruby/object:Gem::Version
|
96
|
-
version:
|
105
|
+
version: 2.3.0
|
97
106
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
107
|
requirements:
|
99
108
|
- - ">="
|
100
109
|
- !ruby/object:Gem::Version
|
101
110
|
version: '0'
|
102
111
|
requirements: []
|
103
|
-
|
104
|
-
|
105
|
-
signing_key:
|
112
|
+
rubygems_version: 3.2.22
|
113
|
+
signing_key:
|
106
114
|
specification_version: 4
|
107
|
-
summary: XZ compression via liblzma for Ruby, using
|
115
|
+
summary: XZ compression via liblzma for Ruby, using fiddle.
|
108
116
|
test_files: []
|
data/COPYING
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
(The MIT License)
|
2
|
-
|
3
|
-
Basic liblzma-bindings for Ruby.
|
4
|
-
|
5
|
-
Copyright © 2011-2014 Marvin Gülker et al.
|
6
|
-
|
7
|
-
See the file `AUTHORS' for the full list of contributors.
|
8
|
-
|
9
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
10
|
-
a copy of this software and associated documentation files (the
|
11
|
-
‘Software’), to deal in the Software without restriction, including
|
12
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
13
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
14
|
-
permit persons to whom the Software is furnished to do so, subject to
|
15
|
-
the following conditions:
|
16
|
-
|
17
|
-
The above copyright notice and this permission notice shall be
|
18
|
-
included in all copies or substantial portions of the Software.
|
19
|
-
|
20
|
-
THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND,
|
21
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
22
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
23
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
24
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
25
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
26
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|