archive-zip 0.8.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/LICENSE +1 -1
- data/NEWS.md +6 -0
- data/README.md +1 -1
- data/lib/archive/support/time.rb +30 -1
- data/lib/archive/zip/version.rb +1 -1
- data/spec/archive/dos_time_spec.rb +113 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9138f623736687f7bffedd8be706a604ef986143
|
4
|
+
data.tar.gz: 6098fe76a711d2a74aa6a69918eb507fd6de5654
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 319cd9c5e8882d05032abb80e8f6cd6cab9459226eb95be0458caaf950239d1d2d03495d3338af12f1c950fd68fd7e76d33f74af322de520ad64a066b03831f0
|
7
|
+
data.tar.gz: 6763e8e864211d2277d8bcd6a3cec53a2c51a7a4b84f004c4d5a9b4f740cafc714b145537a7fe8faa0f73b90ac398962fbcf390ef30a51f126444ea3a47145d8
|
data/LICENSE
CHANGED
data/NEWS.md
CHANGED
@@ -6,6 +6,12 @@ detailed information is available in the rest of the documentation.
|
|
6
6
|
**NOTE:** Date stamps in the following entries are in YYYY/MM/DD format.
|
7
7
|
|
8
8
|
|
9
|
+
## v0.9.0 (2016/12/18)
|
10
|
+
|
11
|
+
### Fixes
|
12
|
+
|
13
|
+
* Initialize DOSTime correctly when not given a struct to parse.
|
14
|
+
|
9
15
|
## v0.8.0 (2015/01/05)
|
10
16
|
|
11
17
|
### Fixes
|
data/README.md
CHANGED
@@ -228,7 +228,7 @@ be more easily accepted if they are consistent with the rest of the code.
|
|
228
228
|
```
|
229
229
|
(The MIT License)
|
230
230
|
|
231
|
-
Copyright (c)
|
231
|
+
Copyright (c) 2016 Jeremy Bopp
|
232
232
|
|
233
233
|
Permission is hereby granted, free of charge, to any person obtaining
|
234
234
|
a copy of this software and associated documentation files (the
|
data/lib/archive/support/time.rb
CHANGED
@@ -45,7 +45,7 @@ module Archive
|
|
45
45
|
def initialize(dos_time = nil)
|
46
46
|
case dos_time
|
47
47
|
when nil
|
48
|
-
@dos_time = Time.now.to_dos_time.
|
48
|
+
@dos_time = Time.now.to_dos_time.to_i
|
49
49
|
when Integer
|
50
50
|
@dos_time = dos_time
|
51
51
|
else
|
@@ -54,6 +54,8 @@ module Archive
|
|
54
54
|
end
|
55
55
|
@dos_time = dos_time.unpack('V')[0]
|
56
56
|
end
|
57
|
+
|
58
|
+
validate
|
57
59
|
end
|
58
60
|
|
59
61
|
# Returns -1 if _other_ is a time earlier than this one, 0 if _other_ is the
|
@@ -86,5 +88,32 @@ module Archive
|
|
86
88
|
year = ((0b1111111 << 25 & @dos_time) >> 25) + 1980
|
87
89
|
return Time.local(year, month, day, hour, minute, second)
|
88
90
|
end
|
91
|
+
|
92
|
+
private
|
93
|
+
|
94
|
+
def validate
|
95
|
+
second = (0b11111 & @dos_time)
|
96
|
+
minute = (0b111111 << 5 & @dos_time) >> 5
|
97
|
+
hour = (0b11111 << 11 & @dos_time) >> 11
|
98
|
+
day = (0b11111 << 16 & @dos_time) >> 16
|
99
|
+
month = (0b1111 << 21 & @dos_time) >> 21
|
100
|
+
year = (0b1111111 << 25 & @dos_time) >> 25
|
101
|
+
|
102
|
+
if second > 29
|
103
|
+
raise ArgumentError, 'second must not be greater than 29'
|
104
|
+
elsif minute > 59
|
105
|
+
raise ArgumentError, 'minute must not be greater than 59'
|
106
|
+
elsif hour > 24
|
107
|
+
raise ArgumentError, 'hour must not be greater than 24'
|
108
|
+
elsif day < 1
|
109
|
+
raise ArgumentError, 'day must not be less than 1'
|
110
|
+
elsif month < 1
|
111
|
+
raise ArgumentError, 'month must not be less than 1'
|
112
|
+
elsif month > 12
|
113
|
+
raise ArgumentError, 'month must not be greater than 12'
|
114
|
+
elsif year > 119
|
115
|
+
raise ArgumentError, 'year must not be greater than 119'
|
116
|
+
end
|
117
|
+
end
|
89
118
|
end
|
90
119
|
end
|
data/lib/archive/zip/version.rb
CHANGED
@@ -0,0 +1,113 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require 'minitest/autorun'
|
4
|
+
|
5
|
+
require 'archive/support/time'
|
6
|
+
|
7
|
+
describe 'Archive::DOSTime.new' do
|
8
|
+
let(:epoc) { 0b0000000_0001_00001_00000_000000_00000 }
|
9
|
+
let(:end_times) { 0b1110111_1100_11111_11000_111011_11101 }
|
10
|
+
|
11
|
+
it 'uses the current time when no structure is given' do
|
12
|
+
now = Time.now.localtime
|
13
|
+
dos_time = Archive::DOSTime.new.to_time
|
14
|
+
|
15
|
+
now.year.must_be_close_to(dos_time.year, 1)
|
16
|
+
now.month.must_be_close_to(dos_time.month, 1)
|
17
|
+
now.day.must_be_close_to(dos_time.day, 1)
|
18
|
+
now.hour.must_be_close_to(dos_time.hour, 1)
|
19
|
+
now.min.must_be_close_to(dos_time.min, 1)
|
20
|
+
now.sec.must_be_close_to(dos_time.sec, 3)
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'accepts valid Integer structures' do
|
24
|
+
Archive::DOSTime.new(epoc)
|
25
|
+
Archive::DOSTime.new(end_times)
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'accepts valid String structures' do
|
29
|
+
Archive::DOSTime.new([epoc].pack('V'))
|
30
|
+
Archive::DOSTime.new([end_times].pack('V'))
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'rejects invalid Integer structures' do
|
34
|
+
# Second must not be greater than 29.
|
35
|
+
proc {
|
36
|
+
Archive::DOSTime.new(epoc | 0b0000000_0000_00000_00000_000000_11110)
|
37
|
+
}.must_raise(ArgumentError)
|
38
|
+
|
39
|
+
# Minute must not be greater than 59.
|
40
|
+
proc {
|
41
|
+
Archive::DOSTime.new(epoc | 0b0000000_0000_00000_00000_111100_00000)
|
42
|
+
}.must_raise(ArgumentError)
|
43
|
+
|
44
|
+
# Hour must not be greater than 24.
|
45
|
+
proc {
|
46
|
+
Archive::DOSTime.new(epoc | 0b0000000_0000_00000_11001_000000_00000)
|
47
|
+
}.must_raise(ArgumentError)
|
48
|
+
|
49
|
+
# Day must not be zero.
|
50
|
+
proc {
|
51
|
+
Archive::DOSTime.new(epoc & 0b1111111_1111_00000_11111_111111_11111)
|
52
|
+
}.must_raise(ArgumentError)
|
53
|
+
|
54
|
+
# Month must not be zero.
|
55
|
+
proc {
|
56
|
+
Archive::DOSTime.new(epoc & 0b1111111_0000_11111_11111_111111_11111)
|
57
|
+
}.must_raise(ArgumentError)
|
58
|
+
|
59
|
+
# Month must not be greater than 12.
|
60
|
+
proc {
|
61
|
+
Archive::DOSTime.new(epoc | 0b0000000_1101_00000_00000_000000_00000)
|
62
|
+
}.must_raise(ArgumentError)
|
63
|
+
|
64
|
+
# Year must not be greater than 119.
|
65
|
+
proc {
|
66
|
+
Archive::DOSTime.new(epoc | 0b1111000_0000_00000_00000_000000_00000)
|
67
|
+
}.must_raise(ArgumentError)
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'rejects invalid String structures' do
|
71
|
+
# Second must not be greater than 29.
|
72
|
+
proc {
|
73
|
+
packed = [epoc | 0b0000000_0000_00000_00000_000000_11110].pack('V')
|
74
|
+
Archive::DOSTime.new(packed)
|
75
|
+
}.must_raise(ArgumentError)
|
76
|
+
|
77
|
+
# Minute must not be greater than 59.
|
78
|
+
proc {
|
79
|
+
packed = [epoc | 0b0000000_0000_00000_00000_111100_00000].pack('V')
|
80
|
+
Archive::DOSTime.new(packed)
|
81
|
+
}.must_raise(ArgumentError)
|
82
|
+
|
83
|
+
# Hour must not be greater than 24.
|
84
|
+
proc {
|
85
|
+
packed = [epoc | 0b0000000_0000_00000_11001_000000_00000].pack('V')
|
86
|
+
Archive::DOSTime.new(packed)
|
87
|
+
}.must_raise(ArgumentError)
|
88
|
+
|
89
|
+
# Day must not be zero.
|
90
|
+
proc {
|
91
|
+
packed = [epoc & 0b1111111_1111_00000_11111_111111_11111].pack('V')
|
92
|
+
Archive::DOSTime.new(packed)
|
93
|
+
}.must_raise(ArgumentError)
|
94
|
+
|
95
|
+
# Month must not be zero.
|
96
|
+
proc {
|
97
|
+
packed = [epoc & 0b1111111_0000_11111_11111_111111_11111].pack('V')
|
98
|
+
Archive::DOSTime.new(packed)
|
99
|
+
}.must_raise(ArgumentError)
|
100
|
+
|
101
|
+
# Month must not be greater than 12.
|
102
|
+
proc {
|
103
|
+
packed = [epoc | 0b0000000_1101_00000_00000_000000_00000].pack('V')
|
104
|
+
Archive::DOSTime.new(packed)
|
105
|
+
}.must_raise(ArgumentError)
|
106
|
+
|
107
|
+
# Year must not be greater than 119.
|
108
|
+
proc {
|
109
|
+
packed = [epoc | 0b1111000_0000_00000_00000_000000_00000].pack('V')
|
110
|
+
Archive::DOSTime.new(packed)
|
111
|
+
}.must_raise(ArgumentError)
|
112
|
+
end
|
113
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: archive-zip
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremy Bopp
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-
|
12
|
+
date: 2016-12-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: io-like
|
@@ -147,6 +147,7 @@ files:
|
|
147
147
|
- lib/archive/zip/extra_field/raw.rb
|
148
148
|
- lib/archive/zip/extra_field/unix.rb
|
149
149
|
- lib/archive/zip/version.rb
|
150
|
+
- spec/archive/dos_time_spec.rb
|
150
151
|
- spec/archive/zip/archive_spec.rb
|
151
152
|
- spec/archive/zip/codec/deflate/compress/checksum_spec.rb
|
152
153
|
- spec/archive/zip/codec/deflate/compress/close_spec.rb
|
@@ -273,6 +274,7 @@ signing_key:
|
|
273
274
|
specification_version: 4
|
274
275
|
summary: Simple, extensible, pure Ruby ZIP archive support.
|
275
276
|
test_files:
|
277
|
+
- spec/archive/dos_time_spec.rb
|
276
278
|
- spec/archive/zip/archive_spec.rb
|
277
279
|
- spec/archive/zip/codec/deflate/compress/checksum_spec.rb
|
278
280
|
- spec/archive/zip/codec/deflate/compress/close_spec.rb
|