Skip to content

Commit

Permalink
Updated for Crystal 0.35.0
Browse files Browse the repository at this point in the history
  • Loading branch information
naqvis committed Jun 11, 2020
1 parent a36e71b commit 3f53a40
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 23 deletions.
10 changes: 3 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ Crystal bindings to the XZ (lzma) compression library.
require "xz"
```

`XZ` shard provides both `XZ::Reader` and `XZ::Writer`.
`XZ` shard provides both `Compress::XZ::Reader` and `Compress::XZ::Writer`.

## Example: decompress an xz file
#
```crystal
require "xz"
string = File.open("file.xz") do |file|
XZ::Reader.open(file) do |xz|
Compress::XZ::Reader.open(file) do |xz|
xz.gets_to_end
end
end
Expand All @@ -44,17 +44,13 @@ File.write("file.txt", "abcd")
File.open("./file.txt", "r") do |input_file|
File.open("./file.xz", "w") do |output_file|
XZ::Writer.open(output_file) do |xz|
Compress::XZ::Writer.open(output_file) do |xz|
IO.copy(input_file, xz)
end
end
end
```

## Development

TODO: Write development instructions here

## Contributing

1. Fork it (<https://github.com/naqvis/xz.cr/fork>)
Expand Down
4 changes: 2 additions & 2 deletions shard.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
name: xz
version: 0.1.1
version: 0.1.2

authors:
- Ali Naqvi <syed.alinaqvi@gmail.com>
description: |
Crystal bindings to the XZ (lzma) compression library.
crystal: 0.34.0
crystal: 0.35.0

license: MIT
10 changes: 5 additions & 5 deletions spec/xz_spec.cr
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
require "./spec_helper"
require "file_utils"
describe XZ do
describe Compress::XZ do
it "Test Round Trip" do
compressed_io = IO::Memory.new
str = "The quick brown fox jumps over the lazy dog."
XZ::Writer.open(compressed_io) do |zw|
Compress::XZ::Writer.open(compressed_io) do |zw|
zw.write str.to_slice
end
compressed_io.rewind
uncompressed = XZ::Reader.open(compressed_io) do |zr|
uncompressed = Compress::XZ::Reader.open(compressed_io) do |zr|
zr.gets_to_end
end
uncompressed.should eq(str)
Expand All @@ -17,14 +17,14 @@ describe XZ do
it "Test write/Read file" do
File.open("./LICENSE", "r") do |input_file|
File.open("./LICENSE.xz", "w") do |output_file|
XZ::Writer.open(output_file) do |xz|
Compress::XZ::Writer.open(output_file) do |xz|
IO.copy(input_file, xz)
end
end
end
expected = File.read("./LICENSE")
got = File.open("./LICENSE.xz") do |file|
XZ::Reader.open(file) do |xz|
Compress::XZ::Reader.open(file) do |xz|
xz.gets_to_end
end
end
Expand Down
4 changes: 2 additions & 2 deletions src/xz.cr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# XZ Crystal Wrapper
require "semantic_version"

module XZ
VERSION = "0.1.1"
module Compress::XZ
VERSION = "0.1.2"

LZMA_VERSION = SemanticVersion.parse String.new(LZMA.version_string)
LZMA_VERSION_MINIMUM = SemanticVersion.parse("5.2.4")
Expand Down
2 changes: 1 addition & 1 deletion src/xz/lib.cr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module XZ
module Compress::XZ
@[Link(ldflags: "`command -v pkg-config > /dev/null && pkg-config --libs liblzma 2> /dev/null|| printf %s '--llzma'`")]
lib LZMA
alias Uint8T = UInt8
Expand Down
4 changes: 2 additions & 2 deletions src/xz/reader.cr
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
# require "xz"

# string = File.open("file.xz") do |file|
# XZ::Reader.open(file) do |xz|
# Compress::XZ::Reader.open(file) do |xz|
# xz.gets_to_end
# end
# end
# pp string
# ```

class XZ::Reader < IO
class Compress::XZ::Reader < IO
LZMA_CONCATENATED = 0x08
include IO::Buffered

Expand Down
9 changes: 5 additions & 4 deletions src/xz/writer.cr
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
#
# File.open("./file.txt", "r") do |input_file|
# File.open("./file.xz", "w") do |output_file|
# XZ::Writer.open(output_file) do |xz|
# Compress::XZ::Writer.open(output_file) do |xz|
# IO.copy(input_file, xz)
# end
# end
# end
# ```
class XZ::Writer < IO
class Compress::XZ::Writer < IO
# If `#sync_close?` is `true`, closing this IO will close the underlying IO.
property? sync_close : Bool

Expand Down Expand Up @@ -80,14 +80,15 @@ class XZ::Writer < IO
end

# See `IO#write`.
def write(slice : Bytes) : Nil
def write(slice : Bytes) : Int64
check_open

return if slice.empty?
return 0i64 if slice.empty?

@stream.next_in = slice.to_unsafe
@stream.avail_in = slice.size
do_action LZMA::Action::Run
slice.size.to_i64
end

# See `IO#flush`.
Expand Down

0 comments on commit 3f53a40

Please sign in to comment.