diff --git a/shard.yml b/shard.yml index f2f7afa..a7750d0 100644 --- a/shard.yml +++ b/shard.yml @@ -1,10 +1,10 @@ name: crystar -version: 0.1.5 +version: 0.1.6 description: | Shard Crystar implements access to tar archives. This shard aims to cover most variations of the format, including those produced by GNU and BSD tar tools. authors: - Ali Naqvi -crystal: 0.34.0 +crystal: 0.35.0 license: MIT diff --git a/src/crystar.cr b/src/crystar.cr index dae5534..5c69636 100644 --- a/src/crystar.cr +++ b/src/crystar.cr @@ -35,7 +35,7 @@ require "./tar/*" # end # ``` module Crystar - VERSION = "0.1.5" + VERSION = "0.1.6" # Common Crystar exceptions class Error < Exception diff --git a/src/tar/reader.cr b/src/tar/reader.cr index ba33785..c62395f 100644 --- a/src/tar/reader.cr +++ b/src/tar/reader.cr @@ -369,7 +369,7 @@ module Crystar abstract def read(b : Bytes) : Int abstract def write_to(w : IO) : Int - def write(b : Bytes) : Nil + def write(b : Bytes) : Int64 raise Error.new "Crystar Reader: Can't write" end diff --git a/src/tar/writer.cr b/src/tar/writer.cr index d66a5ce..8c11515 100644 --- a/src/tar/writer.cr +++ b/src/tar/writer.cr @@ -114,7 +114,7 @@ module Crystar # Calling write on special types like LINK, SYMLINK, CHAR, # BLOCK, DIR, and FIFO returns (0, ErrWriteTooLong) regardless # of what the Header#size claims. - def write(b : Bytes) : Nil + def write(b : Bytes) : Int64 raise Error.new("Can't write to closed writer") if @closed # begin @curr.write(b) @@ -349,7 +349,7 @@ module Crystar def initialize(@io) end - abstract def write(b : Bytes) : Nil + abstract def write(b : Bytes) : Int64 abstract def read_from(r : IO) : Int def read(b : Bytes) @@ -367,7 +367,7 @@ module Crystar super(@io) end - def write(b : Bytes) : Nil + def write(b : Bytes) : Int64 overwrite = b.size > @nb b = b[..@nb] if overwrite if b.size > 0 @@ -375,7 +375,7 @@ module Crystar @nb -= b.size end raise ErrWriteTooLong.new "tar: write too long" if overwrite - nil + b.size.to_i64 end def read_from(r : IO) : Int @@ -396,11 +396,10 @@ module Crystar super(@fw) end - def write(b : Bytes) : Nil + def write(b : Bytes) : Int64 overwrite = b.size > logical_remaining b = b[...logical_remaining] if overwrite - - b0 = b + written = 0i64 end_pos = @pos + b.size too_long = false while end_pos > @pos && !too_long @@ -422,12 +421,12 @@ module Crystar end b = b[nf..] @pos += nf + written += nf if @pos >= data_end && @sp.size > 1 @sp = @sp[1..] # Ensure last fragment always remains end end - n = b0.size - b.size # Not possible; implies bug in validation logic raise Error.new("sparse file references non-existent data") if too_long if logical_remaining == 0 && physical_remaining > 0 @@ -435,7 +434,7 @@ module Crystar raise Error.new("sparse file contains unreferenced data") end raise IO::EOFError.new if overwrite - n + written end def read_from(r : IO) : Int