File tree Expand file tree Collapse file tree 7 files changed +20
-23
lines changed Expand file tree Collapse file tree 7 files changed +20
-23
lines changed Original file line number Diff line number Diff line change @@ -20,15 +20,15 @@ Crystal bindings to the XZ (lzma) compression library.
20
20
require "xz"
21
21
` ` `
22
22
23
- ` XZ` shard provides both `XZ::Reader` and `XZ::Writer`.
23
+ ` XZ` shard provides both `Compress:: XZ::Reader` and `Compress:: XZ::Writer`.
24
24
25
25
# # Example: decompress an xz file
26
26
#
27
27
` ` ` crystal
28
28
require "xz"
29
29
30
30
string = File.open("file.xz") do |file|
31
- XZ::Reader.open(file) do |xz|
31
+ Compress:: XZ::Reader.open(file) do |xz|
32
32
xz.gets_to_end
33
33
end
34
34
end
@@ -44,17 +44,13 @@ File.write("file.txt", "abcd")
44
44
45
45
File.open("./file.txt", "r") do |input_file|
46
46
File.open("./file.xz", "w") do |output_file|
47
- XZ::Writer.open(output_file) do |xz|
47
+ Compress:: XZ::Writer.open(output_file) do |xz|
48
48
IO.copy(input_file, xz)
49
49
end
50
50
end
51
51
end
52
52
` ` `
53
53
54
- # # Development
55
-
56
- TODO : Write development instructions here
57
-
58
54
# # Contributing
59
55
60
56
1. Fork it (<https://github.com/naqvis/xz.cr/fork>)
Original file line number Diff line number Diff line change 1
1
name : xz
2
- version : 0.1.1
2
+ version : 0.1.2
3
3
4
4
authors :
5
5
6
6
description : |
7
7
Crystal bindings to the XZ (lzma) compression library.
8
8
9
- crystal : 0.34 .0
9
+ crystal : 0.35 .0
10
10
11
11
license : MIT
Original file line number Diff line number Diff line change 1
1
require " ./spec_helper"
2
2
require " file_utils"
3
- describe XZ do
3
+ describe Compress :: XZ do
4
4
it " Test Round Trip" do
5
5
compressed_io = IO ::Memory .new
6
6
str = " The quick brown fox jumps over the lazy dog."
7
- XZ ::Writer .open(compressed_io) do |zw |
7
+ Compress :: XZ ::Writer .open(compressed_io) do |zw |
8
8
zw.write str.to_slice
9
9
end
10
10
compressed_io.rewind
11
- uncompressed = XZ ::Reader .open(compressed_io) do |zr |
11
+ uncompressed = Compress :: XZ ::Reader .open(compressed_io) do |zr |
12
12
zr.gets_to_end
13
13
end
14
14
uncompressed.should eq(str)
@@ -17,14 +17,14 @@ describe XZ do
17
17
it " Test write/Read file" do
18
18
File .open(" ./LICENSE" , " r" ) do |input_file |
19
19
File .open(" ./LICENSE.xz" , " w" ) do |output_file |
20
- XZ ::Writer .open(output_file) do |xz |
20
+ Compress :: XZ ::Writer .open(output_file) do |xz |
21
21
IO .copy(input_file, xz)
22
22
end
23
23
end
24
24
end
25
25
expected = File .read(" ./LICENSE" )
26
26
got = File .open(" ./LICENSE.xz" ) do |file |
27
- XZ ::Reader .open(file) do |xz |
27
+ Compress :: XZ ::Reader .open(file) do |xz |
28
28
xz.gets_to_end
29
29
end
30
30
end
Original file line number Diff line number Diff line change 1
1
# XZ Crystal Wrapper
2
2
require " semantic_version"
3
3
4
- module XZ
5
- VERSION = " 0.1.1 "
4
+ module Compress:: XZ
5
+ VERSION = " 0.1.2 "
6
6
7
7
LZMA_VERSION = SemanticVersion .parse String .new(LZMA .version_string)
8
8
LZMA_VERSION_MINIMUM = SemanticVersion .parse(" 5.2.4" )
Original file line number Diff line number Diff line change 1
- module XZ
1
+ module Compress:: XZ
2
2
@[Link (ldflags: " `command -v pkg-config > /dev/null && pkg-config --libs liblzma 2> /dev/null|| printf %s '--llzma'`" )]
3
3
lib LZMA
4
4
alias Uint8T = UInt8
Original file line number Diff line number Diff line change 8
8
# require "xz"
9
9
10
10
# string = File.open("file.xz") do |file|
11
- # XZ::Reader.open(file) do |xz|
11
+ # Compress:: XZ::Reader.open(file) do |xz|
12
12
# xz.gets_to_end
13
13
# end
14
14
# end
15
15
# pp string
16
16
# ```
17
17
18
- class XZ::Reader < IO
18
+ class Compress:: XZ::Reader < IO
19
19
LZMA_CONCATENATED = 0x08
20
20
include IO ::Buffered
21
21
Original file line number Diff line number Diff line change 15
15
#
16
16
# File.open("./file.txt", "r") do |input_file|
17
17
# File.open("./file.xz", "w") do |output_file|
18
- # XZ::Writer.open(output_file) do |xz|
18
+ # Compress:: XZ::Writer.open(output_file) do |xz|
19
19
# IO.copy(input_file, xz)
20
20
# end
21
21
# end
22
22
# end
23
23
# ```
24
- class XZ::Writer < IO
24
+ class Compress:: XZ::Writer < IO
25
25
# If `#sync_close?` is `true`, closing this IO will close the underlying IO.
26
26
property? sync_close : Bool
27
27
@@ -80,14 +80,15 @@ class XZ::Writer < IO
80
80
end
81
81
82
82
# See `IO#write`.
83
- def write (slice : Bytes ) : Nil
83
+ def write (slice : Bytes ) : Int64
84
84
check_open
85
85
86
- return if slice.empty?
86
+ return 0 i64 if slice.empty?
87
87
88
88
@stream .next_in = slice.to_unsafe
89
89
@stream .avail_in = slice.size
90
90
do_action LZMA ::Action ::Run
91
+ slice.size.to_i64
91
92
end
92
93
93
94
# See `IO#flush`.
You can’t perform that action at this time.
0 commit comments