doo_dah 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.2.0
data/doo_dah.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{doo_dah}
8
- s.version = "0.1.1"
8
+ s.version = "0.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Michael Collas"]
12
- s.date = %q{2012-06-05}
12
+ s.date = %q{2012-06-18}
13
13
  s.description = %q{ This gem creates zip files using the STORE method - i.e. with no compression. This enables the generation of
14
14
  zip files with a known size from streamed data, providing the size of the input files is known.
15
15
  }
@@ -43,23 +43,10 @@ Gem::Specification.new do |s|
43
43
  ]
44
44
  s.homepage = %q{http://github.com/michaelcollas/doo_dah}
45
45
  s.require_paths = ["lib"]
46
- s.rubygems_version = %q{1.3.7}
46
+ s.rubygems_version = %q{1.5.2}
47
47
  s.summary = %q{Creates zip files suitable for streaming.}
48
- s.test_files = [
49
- "spec/central_directory_spec.rb",
50
- "spec/dos_time_spec.rb",
51
- "spec/local_directory_header_spec.rb",
52
- "spec/spec_helper.rb",
53
- "spec/support/byte_matcher.rb",
54
- "spec/support/write_capturing_example_group.rb",
55
- "spec/zip_entry_header_spec.rb",
56
- "spec/zip_entry_spec.rb",
57
- "spec/zip_header_spec.rb",
58
- "spec/zip_output_stream_spec.rb"
59
- ]
60
48
 
61
49
  if s.respond_to? :specification_version then
62
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
63
50
  s.specification_version = 3
64
51
 
65
52
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
@@ -1,25 +1,30 @@
1
1
  require 'rubygems'
2
2
  require 'doo_dah'
3
+ require 'zlib'
3
4
 
4
5
  z = DooDah::ZipOutputStream.new(STDOUT)
5
6
 
6
7
  content = "the name of this file is written in simplified Chinese\n"
7
- z.create_entry('这里插入一个聪明的说', content.size) do |e|
8
+ crc = Zlib::crc32(content, 0)
9
+ z.create_entry('这里插入一个聪明的说', content.size, crc) do |e|
8
10
  e.write_file_data(content)
9
11
  end
10
12
 
11
13
  content = "the name of this file is written in Japanese\n"
12
- z.create_entry('ここに巧妙なことわざを挿入', content.size) do |e|
14
+ crc = Zlib::crc32(content, 0)
15
+ z.create_entry('ここに巧妙なことわざを挿入', content.size, crc) do |e|
13
16
  e.write_file_data(content)
14
17
  end
15
18
 
16
19
  content = "the name of this file is written in Hebrew\n"
17
- z.create_entry('הכנס אומרים חכם פה', content.size) do |e|
20
+ crc = Zlib::crc32(content, 0)
21
+ z.create_entry('הכנס אומרים חכם פה', content.size, crc) do |e|
18
22
  e.write_file_data(content)
19
23
  end
20
24
 
21
25
  content = "the name of this file is written in Arabic\n"
22
- z.create_entry('إدراج قائلا ذكي هنا', content.size) do |e|
26
+ crc = Zlib::crc32(content, 0)
27
+ z.create_entry('إدراج قائلا ذكي هنا', content.size, crc) do |e|
23
28
  e.write_file_data(content)
24
29
  end
25
30
 
@@ -29,7 +34,8 @@ content = "This zip file contains five files (including this one). If the text \
29
34
  "in Arabic. Hebrew and Arabic are both right-to-left reading languages, \n" +
30
35
  "so some zip programs may present a listing that has the whole row \n" +
31
36
  "reversed.\n"
32
- z.create_entry('readme.txt', content.size) do |e|
37
+ crc = Zlib::crc32(content, 0)
38
+ z.create_entry('readme.txt', content.size, crc) do |e|
33
39
  e.write_file_data(content)
34
40
  end
35
41
 
@@ -14,19 +14,19 @@ module DooDah
14
14
  @entries = []
15
15
  end
16
16
 
17
- def create_entry(name, size=0)
17
+ def create_entry(name, size=0, crc=0)
18
18
  raise EntryOpen if entry_open?
19
19
  begin
20
- yield start_entry(name, size)
20
+ yield start_entry(name, size, crc)
21
21
  ensure
22
22
  end_current_entry
23
23
  end
24
24
  end
25
25
 
26
26
  # TODO: take block instead of using a start/end method pair?
27
- def start_entry(name, size=0)
27
+ def start_entry(name, size=0, crc=0)
28
28
  end_current_entry
29
- new_entry = ZipEntry.new(self, name, size)
29
+ new_entry = ZipEntry.new(self, name, size, crc)
30
30
  @entries << new_entry
31
31
  new_entry
32
32
  end
@@ -14,9 +14,24 @@ module DooDah
14
14
  describe '#start_entry' do
15
15
 
16
16
  it 'should create a ZipEntry with the zip output stream as its owner' do
17
- ZipEntry.should_receive(:new).with(@zip, 'entry name', 123)
17
+ ZipEntry.should_receive(:new).with(@zip, 'entry name', 0, 0)
18
+ @zip.start_entry('entry name')
19
+ end
20
+
21
+ it 'should create the ZipEntry with 0 size and crc if neither are specified' do
22
+ ZipEntry.should_receive(:new).with(@zip, 'entry name', 0, 0)
23
+ @zip.start_entry('entry name')
24
+ end
25
+
26
+ it 'should create the ZipEntry with a pre-determined size if specified' do
27
+ ZipEntry.should_receive(:new).with(@zip, 'entry name', 123, 0)
18
28
  @zip.start_entry('entry name', 123)
19
29
  end
30
+
31
+ it 'should create the ZipEntry with a pre-determined crc if specified' do
32
+ ZipEntry.should_receive(:new).with(@zip, 'entry name', 0, 9876543210)
33
+ @zip.start_entry('entry name', 0, 9876543210)
34
+ end
20
35
 
21
36
  it 'should return the new entry' do
22
37
  @zip.start_entry('entry name', 123).should == @entry
@@ -33,26 +48,26 @@ module DooDah
33
48
  describe '#create_entry' do
34
49
 
35
50
  it 'should create a new ZipEntry' do
36
- ZipEntry.should_receive(:new).with(@zip, 'entry name', 123)
37
- @zip.create_entry('entry name', 123) {}
51
+ ZipEntry.should_receive(:new).with(@zip, 'entry name', 0, 0)
52
+ @zip.create_entry('entry name') {}
38
53
  end
39
54
 
40
55
  it 'should yield the new entry to a block' do
41
56
  yielded_zip_entry = nil
42
- @zip.create_entry('entry name', 123) {|zip_entry| yielded_zip_entry = zip_entry}
57
+ @zip.create_entry('entry name') {|zip_entry| yielded_zip_entry = zip_entry}
43
58
  yielded_zip_entry.should == @entry
44
59
  end
45
60
 
46
61
  it 'should close the new entry on return from the block' do
47
62
  @entry.should_receive(:close)
48
- @zip.create_entry('entry name', 123) {}
63
+ @zip.create_entry('entry name') {}
49
64
  end
50
65
 
51
66
  it 'should close the new entry if an exception is raised during execution of the provided block' do
52
67
  @entry.should_receive(:close)
53
68
  expected_error = Class.new(Exception)
54
69
  begin
55
- @zip.create_entry('entry name', 123) { |zip_entry| raise expected_error }
70
+ @zip.create_entry('entry name') { |zip_entry| raise expected_error }
56
71
  rescue expected_error
57
72
  end
58
73
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: doo_dah
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
5
- prerelease: false
4
+ hash: 23
5
+ prerelease:
6
6
  segments:
7
7
  - 0
8
- - 1
9
- - 1
10
- version: 0.1.1
8
+ - 2
9
+ - 0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Michael Collas
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-06-05 00:00:00 +10:00
18
+ date: 2012-06-18 00:00:00 +10:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -127,18 +127,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
127
127
  requirements: []
128
128
 
129
129
  rubyforge_project:
130
- rubygems_version: 1.3.7
130
+ rubygems_version: 1.5.2
131
131
  signing_key:
132
132
  specification_version: 3
133
133
  summary: Creates zip files suitable for streaming.
134
- test_files:
135
- - spec/central_directory_spec.rb
136
- - spec/dos_time_spec.rb
137
- - spec/local_directory_header_spec.rb
138
- - spec/spec_helper.rb
139
- - spec/support/byte_matcher.rb
140
- - spec/support/write_capturing_example_group.rb
141
- - spec/zip_entry_header_spec.rb
142
- - spec/zip_entry_spec.rb
143
- - spec/zip_header_spec.rb
144
- - spec/zip_output_stream_spec.rb
134
+ test_files: []
135
+