and_feathers-gzipped_tarball 1.0.0.pre

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 50537c080c30e80fe95ec59895f718b91d94d0b8
4
+ data.tar.gz: 1081f32ade22c09dd75b343fc6ead644dc518705
5
+ SHA512:
6
+ metadata.gz: 62e24bc8013fcbafbd1e7bc073a68847a8d382051486f410c85b4beb130302bf5eb7ed6085c578f165ed34fa16494d896602c5c477205888d5e60e440243f3a6
7
+ data.tar.gz: bd127b425a4a0db0f236ad0db6b75f1e8b3d5373a096036d202920231cb26c3528f4030fe251929b1b9aefac540b8ced6442d52da8f1602b27af0421645e6667
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .ruby-version
data/.rspec ADDED
@@ -0,0 +1,5 @@
1
+ -I spec
2
+ -I lib
3
+ --color
4
+ -r byebug
5
+ -r support/cleanliness
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'byebug'
4
+
5
+ # Specify your gem's dependencies in and_feathers-gzipped_tarball.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Brian Cobb
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,52 @@
1
+ # AndFeathers::GzippedTarball
2
+
3
+ Works with [and-feathers](http://github.com/bcobb/and_feathers) to turn in-memory archives into gzipped tarballs.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'and_feathers-gzipped_tarball'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install and_feathers-gzipped_tarball
18
+
19
+ ## Usage
20
+
21
+ ### Writing a tarball to disk
22
+
23
+ ```ruby
24
+ reqiure 'and_feathers'
25
+ require 'and_feathers/gzipped_tarball'
26
+
27
+ # This is a simple archive
28
+ archive = AndFeathers.build('archive') do |root|
29
+ root.file('README')
30
+ end
31
+
32
+ File.open('archive.tgz', 'w+') do |f|
33
+ f << archive.to_io(AndFeathers::GzippedTarball).read
34
+ end
35
+ ```
36
+
37
+ ### Tar an existing directory, plus a few changes/additions
38
+
39
+ ```ruby
40
+ reqiure 'and_feathers'
41
+ require 'and_feathers/gzipped_tarball'
42
+
43
+ archive = AndFeathers.from_path('spec') do |spec|
44
+ spec.file('end_to_end_spec.rb') { '# whoops' }
45
+ spec.file('spec_helper.rb') { '# everyone needs one of these' }
46
+ spec.file('and_feathers/zip
47
+ end
48
+
49
+ File.open('spec.zip', 'w+') do |f|
50
+ f << archive.to_io(AndFeathers::GzippedTarball).read
51
+ end
52
+ ```
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'and_feathers/gzipped_tarball/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "and_feathers-gzipped_tarball"
8
+ spec.version = AndFeathers::GzippedTarball::VERSION
9
+ spec.authors = ["Brian Cobb"]
10
+ spec.email = ["bcobb@uwalumni.com"]
11
+ spec.description = %q{Turn AndFeathers archives into tgz archives}
12
+ spec.summary = %q{Tar and gzip AndFeathers archives}
13
+ spec.homepage = "http://github.com/bcobb/and_feathers-gzipped_tarball"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.test_files = spec.files.grep(%r{^spec/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.3"
21
+ spec.add_development_dependency "rake"
22
+ spec.add_development_dependency "rspec"
23
+ spec.add_development_dependency "and_feathers", ">= 1.0.0.pre", "< 2"
24
+ end
@@ -0,0 +1,64 @@
1
+ require 'rubygems/package'
2
+ require 'zlib'
3
+
4
+ module AndFeathers
5
+ #
6
+ # Conforms to the interface expected by +Archive#to_io+ in the service of
7
+ # turning +Archive+s into gzipped tarballs
8
+ #
9
+ class GzippedTarball
10
+ #
11
+ # Yields a +GzippedTarball+ ready for adding files and directories.
12
+ #
13
+ # @yieldparam package [GzippedTarball]
14
+ #
15
+ # @return [StringIO]
16
+ #
17
+ def self.open(&block)
18
+ tarball_io = StringIO.new("")
19
+
20
+ Gem::Package::TarWriter.new(tarball_io) do |tar|
21
+ yield new(tar)
22
+ end
23
+
24
+ gzip_io = StringIO.new("")
25
+
26
+ Zlib::GzipWriter.new(gzip_io).tap do |writer|
27
+ writer.write(tarball_io.tap(&:rewind).string)
28
+ writer.close
29
+ end
30
+
31
+ StringIO.new(gzip_io.string)
32
+ end
33
+
34
+ #
35
+ # Creates a new +GzippedTarball+. Provides the interface required by
36
+ # +AndFeathers::Directory#to_io+
37
+ #
38
+ # @param tarball [Gem::Package::TarWriter]
39
+ #
40
+ def initialize(tarball)
41
+ @tarball = tarball
42
+ end
43
+
44
+ #
45
+ # Adds the given file to the tarball
46
+ #
47
+ # @param file [AndFeathers::File]
48
+ #
49
+ def add_file(file)
50
+ @tarball.add_file(file.path, file.mode) do |tarred_file|
51
+ tarred_file.write file.read
52
+ end
53
+ end
54
+
55
+ #
56
+ # Adds the given directory to the tarball
57
+ #
58
+ # @param directory [AndFeathers::Directory]
59
+ #
60
+ def add_directory(directory)
61
+ @tarball.mkdir(directory.path, directory.mode)
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,11 @@
1
+ module AndFeathers
2
+ class GzippedTarball
3
+ #
4
+ # and_feathers-gzipped_tarball is versioned independently of and_feathers.
5
+ # The only breaking change in and_feathers that would affect
6
+ # and_feathers-gzipped_tarball at this point is a change to the protocol
7
+ # expected of the argument passed to +AndFeathers::Archive#to_io+
8
+ #
9
+ VERSION = "1.0.0.pre"
10
+ end
11
+ end
@@ -0,0 +1,126 @@
1
+ require 'and_feathers'
2
+ require 'and_feathers/gzipped_tarball'
3
+ require 'support/in_memory_gzipped_tarball'
4
+
5
+ describe AndFeathers do
6
+
7
+ describe 'an archive with a base directory' do
8
+ let(:archive) do
9
+ AndFeathers.build('redis') do |redis|
10
+ redis.dir('cookbooks') do |cookbooks|
11
+ cookbooks.dir('redis') do |redis|
12
+ redis.file('README') { 'README contents' }
13
+ redis.file('CHANGELOG') { 'CHANGELOG contents' }
14
+ redis.file('metadata.rb') { 'metadata.rb contents' }
15
+ redis.dir('recipes') do |recipes|
16
+ recipes.file('default.rb') { 'default.rb contents' }
17
+ end
18
+ redis.dir('templates') do |templates|
19
+ templates.dir('default')
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+
26
+ let(:tree) do
27
+ [
28
+ './redis',
29
+ './redis/cookbooks',
30
+ './redis/cookbooks/redis',
31
+ './redis/cookbooks/redis/README',
32
+ './redis/cookbooks/redis/CHANGELOG',
33
+ './redis/cookbooks/redis/metadata.rb',
34
+ './redis/cookbooks/redis/recipes',
35
+ './redis/cookbooks/redis/recipes/default.rb',
36
+ './redis/cookbooks/redis/templates',
37
+ './redis/cookbooks/redis/templates/default'
38
+ ]
39
+ end
40
+
41
+ it 'can build an in-memory tarred/gzipped IO stream' do
42
+ tarball = archive.to_io(AndFeathers::GzippedTarball)
43
+ reader = InMemoryGzippedTarball.new(tarball)
44
+
45
+ expect(reader.to_a.map(&:first)).to eql(tree)
46
+ expect(reader.to_a.map(&:last).reject(&:empty?)).to eq([
47
+ 'README contents',
48
+ 'CHANGELOG contents',
49
+ 'metadata.rb contents',
50
+ 'default.rb contents'
51
+ ])
52
+ end
53
+
54
+ it 'produces an in-memory IO stream that can be saved to disk' do
55
+ file = ::File.join("spec", "tmp", "#{Time.now.to_f}.tgz")
56
+
57
+ tarball = archive.to_io(AndFeathers::GzippedTarball)
58
+
59
+ ::File.open(file, 'w+') { |f| f << tarball.read }
60
+
61
+ reader = InMemoryGzippedTarball.new(::File.open(file))
62
+
63
+ expect(reader.to_a.map(&:first)).to eql(tree)
64
+ end
65
+ end
66
+
67
+ describe 'an archive without a base directory' do
68
+ let(:archive) do
69
+ AndFeathers.build do |redis|
70
+ redis.dir('cookbooks') do |cookbooks|
71
+ cookbooks.dir('redis') do |redis|
72
+ redis.file('README') { 'README contents' }
73
+ redis.file('CHANGELOG') { 'CHANGELOG contents' }
74
+ redis.file('metadata.rb') { 'metadata.rb contents' }
75
+ redis.dir('recipes') do |recipes|
76
+ recipes.file('default.rb') { 'default.rb contents' }
77
+ end
78
+ redis.dir('templates') do |templates|
79
+ templates.dir('default')
80
+ end
81
+ end
82
+ end
83
+ end
84
+ end
85
+
86
+ let(:tree) do
87
+ [
88
+ '.',
89
+ './cookbooks',
90
+ './cookbooks/redis',
91
+ './cookbooks/redis/README',
92
+ './cookbooks/redis/CHANGELOG',
93
+ './cookbooks/redis/metadata.rb',
94
+ './cookbooks/redis/recipes',
95
+ './cookbooks/redis/recipes/default.rb',
96
+ './cookbooks/redis/templates',
97
+ './cookbooks/redis/templates/default'
98
+ ]
99
+ end
100
+
101
+ it 'can build an in-memory tarred/gzipped IO stream' do
102
+ tarball = archive.to_io(AndFeathers::GzippedTarball)
103
+ reader = InMemoryGzippedTarball.new(tarball)
104
+
105
+ expect(reader.to_a.map(&:first)).to eql(tree)
106
+ expect(reader.to_a.map(&:last).reject(&:empty?)).to eq([
107
+ 'README contents',
108
+ 'CHANGELOG contents',
109
+ 'metadata.rb contents',
110
+ 'default.rb contents'
111
+ ])
112
+ end
113
+
114
+ it 'produces an in-memory IO stream that can be saved to disk' do
115
+ file = ::File.join("spec", "tmp", "#{Time.now.to_f}.tgz")
116
+
117
+ tarball = archive.to_io(AndFeathers::GzippedTarball)
118
+
119
+ ::File.open(file, 'w+') { |f| f << tarball.read }
120
+
121
+ reader = InMemoryGzippedTarball.new(::File.open(file))
122
+
123
+ expect(reader.to_a.map(&:first)).to eql(tree)
124
+ end
125
+ end
126
+ end
@@ -0,0 +1,7 @@
1
+ RSpec.configure do |config|
2
+ config.after(:suite) do
3
+ Dir['spec/tmp/*.{zip,tgz}'].each do |archive|
4
+ File.unlink(archive)
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,35 @@
1
+ require 'rubygems/package'
2
+ require 'zlib'
3
+
4
+ class InMemoryGzippedTarball
5
+ include Enumerable
6
+
7
+ NotUnzipped = Object.new
8
+
9
+ def initialize(file)
10
+ @file = file
11
+ @unzipped = NotUnzipped
12
+ end
13
+
14
+ def each
15
+ if NotUnzipped == @unzipped
16
+ reader = Zlib::GzipReader.new(@file)
17
+ @unzipped = StringIO.new(reader.read).tap do
18
+ reader.close
19
+ end
20
+ end
21
+
22
+ Gem::Package::TarReader.new(@unzipped)do |tar|
23
+ tar.each do |tarfile|
24
+ if tarfile.directory?
25
+ yield tarfile.full_name, ''
26
+ else
27
+ yield tarfile.full_name, tarfile.read
28
+ end
29
+ end
30
+ end
31
+ ensure
32
+ @unzipped.rewind
33
+ end
34
+ end
35
+
metadata ADDED
@@ -0,0 +1,122 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: and_feathers-gzipped_tarball
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0.pre
5
+ platform: ruby
6
+ authors:
7
+ - Brian Cobb
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-03-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: and_feathers
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: 1.0.0.pre
62
+ - - <
63
+ - !ruby/object:Gem::Version
64
+ version: '2'
65
+ type: :development
66
+ prerelease: false
67
+ version_requirements: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - '>='
70
+ - !ruby/object:Gem::Version
71
+ version: 1.0.0.pre
72
+ - - <
73
+ - !ruby/object:Gem::Version
74
+ version: '2'
75
+ description: Turn AndFeathers archives into tgz archives
76
+ email:
77
+ - bcobb@uwalumni.com
78
+ executables: []
79
+ extensions: []
80
+ extra_rdoc_files: []
81
+ files:
82
+ - .gitignore
83
+ - .rspec
84
+ - Gemfile
85
+ - LICENSE.txt
86
+ - README.md
87
+ - Rakefile
88
+ - and_feathers-gzipped_tarball.gemspec
89
+ - lib/and_feathers/gzipped_tarball.rb
90
+ - lib/and_feathers/gzipped_tarball/version.rb
91
+ - spec/end_to_end_spec.rb
92
+ - spec/support/cleanliness.rb
93
+ - spec/support/in_memory_gzipped_tarball.rb
94
+ homepage: http://github.com/bcobb/and_feathers-gzipped_tarball
95
+ licenses:
96
+ - MIT
97
+ metadata: {}
98
+ post_install_message:
99
+ rdoc_options: []
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - '>='
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - '>'
110
+ - !ruby/object:Gem::Version
111
+ version: 1.3.1
112
+ requirements: []
113
+ rubyforge_project:
114
+ rubygems_version: 2.0.3
115
+ signing_key:
116
+ specification_version: 4
117
+ summary: Tar and gzip AndFeathers archives
118
+ test_files:
119
+ - spec/end_to_end_spec.rb
120
+ - spec/support/cleanliness.rb
121
+ - spec/support/in_memory_gzipped_tarball.rb
122
+ has_rdoc: