diff options
author | Paul Duncan <pabs@pablotron.org> | 2016-08-10 11:56:25 -0400 |
---|---|---|
committer | Paul Duncan <pabs@pablotron.org> | 2016-08-10 11:56:25 -0400 |
commit | c0ced77fb12ecb39bfd680f842fead31cd349831 (patch) | |
tree | 9e02ac26bedd08a9ca73e29f8c7eba20fee22431 /src | |
parent | 478b3581a1e7c3993b0e043b85414929e89a002c (diff) | |
download | zip-crystal-c0ced77fb12ecb39bfd680f842fead31cd349831.tar.bz2 zip-crystal-c0ced77fb12ecb39bfd680f842fead31cd349831.zip |
remove Reader
Diffstat (limited to 'src')
-rw-r--r-- | src/zip.cr | 52 |
1 files changed, 10 insertions, 42 deletions
@@ -1,6 +1,9 @@ require "./zip/*" require "zlib" +# https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT +# http://www.onicos.com/staff/iz/formats/zip.html +# # # TODO: # [x] date/time @@ -1242,63 +1245,28 @@ module Zip end end - class Reader - getter? :closed, :sync_close - getter :zip - - def initialize( - @io : Source, - @pos : UInt32 = 0_u32, - @sync_close : Bool = false, - ) - @closed = false - @zip = Archive.new(@io) - end - - private def assert_open - raise Error.new("already closed") if closed? - end - - def close - assert_open - - @io.close if @sync_close - @closed = true - end - end - def self.read( io : IO, - pos : UInt32 = 0_u32, - sync_close : Bool = false, &cb : Archive -> \ - ) - begin - r = Reader.new(Source.new(io), pos, sync_close) - cb.call(r.zip) - ensure - if r - r.close unless r.closed? - end - end - - nil + ) : Void + r = Archive.new(Source.new(io)) + cb.call(r) end def self.read( slice : Bytes, &cb : Archive -> \ - ) + ) : Void src = Source.new(MemoryIO.new(slice, false)) - read(src, 0_u32, false, &cb) + read(src, &cb) end def self.read( path : String, &cb : Archive -> \ - ) + ) : Void File.open(path, "rb") do |io| - read(io, 0_u32, true, &cb) + read(io, &cb) end end end |