diff options
author | Paul Duncan <pabs@pablotron.org> | 2016-08-07 21:47:31 -0400 |
---|---|---|
committer | Paul Duncan <pabs@pablotron.org> | 2016-08-07 21:47:31 -0400 |
commit | f8099f07f3ff1cbb259acb1f31f0a3975a9c3e93 (patch) | |
tree | c442b6a385c2aeb869deb405bf3d9c33116ee361 /src | |
parent | 09d26629c94f235680ddd11aeb97a44227a1d489 (diff) | |
download | zip-crystal-f8099f07f3ff1cbb259acb1f31f0a3975a9c3e93.tar.bz2 zip-crystal-f8099f07f3ff1cbb259acb1f31f0a3975a9c3e93.zip |
add dos date/time support
Diffstat (limited to 'src')
-rw-r--r-- | src/zip.cr | 19 |
1 files changed, 13 insertions, 6 deletions
@@ -3,7 +3,10 @@ require "zlib" # # TODO: -# [ ] date/time +# [x] date/time +# [x] reader +# [ ] documentation +# [ ] full tests # [ ] zip64 # [ ] legacy unicode (e.g., non-bit 11) path/comment support # [ ] extra data @@ -164,9 +167,13 @@ module Zip module TimeHelper def write_time(io : IO, time : Time) : UInt32 - # TODO - 0_u32.to_u16.to_io(io, LE) - 0_u32.to_u16.to_io(io, LE) + year = Math.max(1980, time.year) - 1980 + + # convert to dos timestamp + (( + (year << 25) | (time.month << 21) | (time.day << 16) | + (time.hour << 11) | (time.minute << 5) | (time.second >> 1) + ) & UInt32::MAX).to_u32.to_io(io, LE) # return number of bytes written 4_u32 @@ -268,7 +275,7 @@ module Zip end # set zlib input buffer - z.next_in = tmp_buf.pointer(0) + z.next_in = tmp_buf.to_unsafe z.avail_in = tmp_buf.size.to_u32 # write compressed data to dst io @@ -299,7 +306,7 @@ module Zip loop do # set zlib output buffer - zp.value.next_out = buf.pointer(0) + zp.value.next_out = buf.to_unsafe zp.value.avail_out = buf.size.to_u32 # compress data (TODO: check for error) |