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 62c85df commit e712cdb
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 13 deletions.
4 changes: 2 additions & 2 deletions shard.yml
Original file line number Diff line number Diff line change
@@ -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 <syed.alinaqvi@gmail.com>

crystal: 0.34.0
crystal: 0.35.0

license: MIT
2 changes: 1 addition & 1 deletion src/crystar.cr
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ require "./tar/*"
# end
# ```
module Crystar
VERSION = "0.1.5"
VERSION = "0.1.6"

# Common Crystar exceptions
class Error < Exception
Expand Down
2 changes: 1 addition & 1 deletion src/tar/reader.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
17 changes: 8 additions & 9 deletions src/tar/writer.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -367,15 +367,15 @@ 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
@io.write(b)
@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
Expand All @@ -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
Expand All @@ -422,20 +421,20 @@ 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
# Not possible; implies bug in validation logic
raise Error.new("sparse file contains unreferenced data")
end
raise IO::EOFError.new if overwrite
n
written
end

def read_from(r : IO) : Int
Expand Down

0 comments on commit e712cdb

Please sign in to comment.