just-keep-zipping 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +21 -0
- data/README.md +34 -0
- data/lib/just-keep-zipping.rb +60 -0
- metadata +61 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: dc550e2a2c93e0959eab63397efdd23c99dc07fe
|
4
|
+
data.tar.gz: f09576ae77642fcb284faac26623ebf741ed89ce
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: aa481e0ef062dbd9ee8e9c861fdf9c13cc7887bdfe63804cca593da3315773ecfc7c4a7263699d5b836e692146d7ca7faa323c3fff17213abcbb29cb5da2b76b
|
7
|
+
data.tar.gz: 2fd58dbbb21d993d613e6e4c86b1cbfd76ece44d81da2f7f2b9bd0b8f1a362e3132e3172a3e7733fa3a97ac4285c100a4124a6805973a34981f7764094bdde51
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Ryan Calhoun
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# just-keep-zipping
|
2
|
+
|
3
|
+
Produce a zip file from many source files, in a streaming or distributed fashion.
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
Make a complete zip of two files
|
8
|
+
|
9
|
+
zip = JustKeepZipping.new
|
10
|
+
zip.add 'file1.txt', 'Data to be zipped'
|
11
|
+
zip.add 'file2.txt', 'More data to be zipped'
|
12
|
+
zip.close
|
13
|
+
|
14
|
+
data = zip.read
|
15
|
+
|
16
|
+
Begin a zip to be continued later
|
17
|
+
|
18
|
+
zip = JustKeepZipping.new
|
19
|
+
zip.add 'file1.txt', 'Data to be zipped'
|
20
|
+
incomplete_data = zip.read
|
21
|
+
progress_data = Marshal.dump zip
|
22
|
+
|
23
|
+
Complete an in-progress zip
|
24
|
+
|
25
|
+
zip = Marshal.load progress_data
|
26
|
+
zip.add 'file2.txt', 'More data to be zipped'
|
27
|
+
zip.close
|
28
|
+
|
29
|
+
ending_data = zip.read
|
30
|
+
|
31
|
+
Assemble the zip
|
32
|
+
|
33
|
+
data = incomplete_data + ending_data
|
34
|
+
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'zip'
|
2
|
+
|
3
|
+
class JustKeepZipping
|
4
|
+
attr_reader :entries
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@entries = []
|
8
|
+
@data = ''
|
9
|
+
end
|
10
|
+
|
11
|
+
def current_size
|
12
|
+
@data.size
|
13
|
+
end
|
14
|
+
|
15
|
+
def add(filename, body)
|
16
|
+
io = Zip::OutputStream.write_buffer do |zip|
|
17
|
+
zip.put_next_entry filename
|
18
|
+
zip.write body.respond_to?(:read) ? body.read : body
|
19
|
+
end
|
20
|
+
io.rewind
|
21
|
+
d = Zip::CentralDirectory.read_from_stream io
|
22
|
+
|
23
|
+
e = d.entries.first
|
24
|
+
payload_size = 30 + e.name.length + e.compressed_size
|
25
|
+
|
26
|
+
io.rewind
|
27
|
+
@data += io.read(payload_size)
|
28
|
+
|
29
|
+
e.zipfile = nil
|
30
|
+
@entries << e
|
31
|
+
nil
|
32
|
+
end
|
33
|
+
|
34
|
+
def close
|
35
|
+
contents_size = 0
|
36
|
+
@entries.each do |e|
|
37
|
+
e.local_header_offset = contents_size
|
38
|
+
contents_size += 30 + e.name.length + e.compressed_size
|
39
|
+
end
|
40
|
+
|
41
|
+
io = StringIO.new
|
42
|
+
io.instance_eval "@offset = #{contents_size}"
|
43
|
+
def io.tell
|
44
|
+
super + @offset
|
45
|
+
end
|
46
|
+
Zip::CentralDirectory.new(@entries).write_to_stream io
|
47
|
+
io.rewind
|
48
|
+
tail = io.read
|
49
|
+
tail.force_encoding 'ASCII-8BIT'
|
50
|
+
@data += tail
|
51
|
+
contents_size
|
52
|
+
end
|
53
|
+
|
54
|
+
def read
|
55
|
+
data = @data
|
56
|
+
@data = ''
|
57
|
+
data
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
metadata
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: just-keep-zipping
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ryan Calhoun
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-11-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rubyzip
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.2'
|
27
|
+
description: Produce a zip archive from a large number of parts, in smaller batches.
|
28
|
+
email:
|
29
|
+
- ryanjamescalhoun@gmail.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- LICENSE
|
35
|
+
- README.md
|
36
|
+
- lib/just-keep-zipping.rb
|
37
|
+
homepage: https://github.com/ryancalhoun/just-keep-zipping
|
38
|
+
licenses:
|
39
|
+
- MIT
|
40
|
+
metadata: {}
|
41
|
+
post_install_message:
|
42
|
+
rdoc_options: []
|
43
|
+
require_paths:
|
44
|
+
- lib
|
45
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0'
|
50
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
requirements: []
|
56
|
+
rubyforge_project:
|
57
|
+
rubygems_version: 2.6.11
|
58
|
+
signing_key:
|
59
|
+
specification_version: 4
|
60
|
+
summary: Just Keep Zipping
|
61
|
+
test_files: []
|