memtar 0.0.1

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: d92f29c592d9d2ec4112e69e04f205a893dbc36b
4
+ data.tar.gz: f61512b2bf45450088ae1f58454319c32811bb4c
5
+ SHA512:
6
+ metadata.gz: 4b0fbe8d37f910acb0727c2eb86dffd62daad06f52d9c4085af4914e10d0e0749b2eab32c5fa4f90d7b3643d0fa3538acfd256a8a76b5a7e08b34f30d29e14dc
7
+ data.tar.gz: 2a6fe9b0a17d1e2dbaf9a5bdc708a9f0cb8ad5a7cc3384d78c092d62c8c58a726ec9c3b58736376f828c1ef5b2b65df648b9f208c1eeb0e54dc5521e73edc9b0
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/.overcommit.yml ADDED
@@ -0,0 +1,31 @@
1
+ # Use this file to configure the Overcommit hooks you wish to use. This will
2
+ # extend the default configuration defined in:
3
+ # https://github.com/causes/overcommit/blob/master/config/default.yml
4
+ #
5
+ # At the topmost level of this YAML file is a key representing type of hook
6
+ # being run (e.g. pre-commit, commit-msg, etc.). Within each type you can
7
+ # customize each hook, such as whether to only run it on certain files (via
8
+ # `include`), whether to only display output if it fails (via `quiet`), etc.
9
+ #
10
+ # For a complete list of hooks, see:
11
+ # https://github.com/causes/overcommit/tree/master/lib/overcommit/hook
12
+ #
13
+ # For a complete list of options that you can use to customize hooks, see:
14
+ # https://github.com/causes/overcommit#configuration
15
+ #
16
+ # Uncomment the following lines to make the configuration take effect.
17
+
18
+ #PreCommit:
19
+ # Rubocop:
20
+ # on_warn: fail # Treat all warnings as failures
21
+ #
22
+ # TrailingWhitespace:
23
+ # exclude:
24
+ # - '**/db/structure.sql' # Ignore trailing whitespace in generated files
25
+ #
26
+ #PostCheckout:
27
+ # ALL: # Special hook name that customizes all hooks of this type
28
+ # quiet: true # Change all post-checkout hooks to only display output on failure
29
+ #
30
+ # IndexTags:
31
+ # enabled: true # Generate a tags file with `ctags` each time HEAD changes
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in memtar.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Rafał Rzepecki
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,44 @@
1
+ # MemTar
2
+
3
+ In-memory tar archive creation
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'memtar'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install memtar
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+
25
+ require 'memtar'
26
+
27
+ archive = MemTar.new
28
+ archive.default[:uname] = "nobody"
29
+
30
+ archive.add_file "foo", "content", mode: 0640
31
+ archive.add_file "bar/baz", "hi!"
32
+ archive.add_symlink "bar/xyzzy", "baz"
33
+ archive.add_file "this", File.new("/etc/passwd") # copies attributes and content
34
+
35
+ File.write "test.tar", archive.to_s
36
+ ```
37
+
38
+ ## Contributing
39
+
40
+ 1. Fork it ( https://github.com/[my-github-username]/memtar/fork )
41
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
42
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
43
+ 4. Push to the branch (`git push origin my-new-feature`)
44
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ begin
4
+ require 'rspec/core/rake_task'
5
+ RSpec::Core::RakeTask.new(:spec)
6
+ rescue LoadError
7
+ task :spec
8
+ end
9
+
10
+ task default: :spec
data/lib/memtar.rb ADDED
@@ -0,0 +1,57 @@
1
+ require 'archive/tar/minitar'
2
+ require 'memtar/version'
3
+
4
+ # In-memory tar archive writer.
5
+ class MemTar
6
+ def initialize
7
+ @io = StringIO.new
8
+ end
9
+
10
+ def add_file path, content, opts = {}
11
+ return add_existing_file path, content if content.is_a?(File) && opts.empty?
12
+ fail ArgumentError, "handling of paths over 100 bytes long not implemented" if path.size > 100
13
+
14
+ size = content.size
15
+ @io.write header opts.merge size: size, name: path
16
+ @io.write content
17
+ @io.write "\0" * (512 - size % 512)
18
+ end
19
+
20
+ def add_symlink path, target
21
+ fail ArgumentError, "handling of paths over 100 bytes long not implemented" if path.size > 100
22
+ @io.write header typeflag: '2', size: 0, mode: 0777, name: path, linkname: target
23
+ end
24
+
25
+ def add_existing_file path, file
26
+ add_file path, file.read, MemTar.opts_of_stat(file.stat)
27
+ end
28
+
29
+ def self.opts_of_stat stat
30
+ uid, gid = [stat.uid, stat.gid]
31
+ {
32
+ mode: stat.mode & 0777,
33
+ uid: uid, gid: gid,
34
+ uname: Etc.getpwuid(uid).name,
35
+ gname: Etc.getgrgid(gid).name,
36
+ mtime: stat.mtime
37
+ }
38
+ end
39
+
40
+ def to_s
41
+ @io.string + "\0" * 1024
42
+ end
43
+
44
+ def header opts
45
+ Archive::Tar::PosixHeader.new(default.merge opts).to_s
46
+ end
47
+
48
+ def default
49
+ @default ||= {
50
+ mode: 0644,
51
+ uid: 0, gid: 0,
52
+ uname: 'wheel', gname: 'wheel',
53
+ mtime: Time.now,
54
+ prefix: ''
55
+ }
56
+ end
57
+ end
@@ -0,0 +1,4 @@
1
+ #
2
+ class MemTar
3
+ VERSION = "0.0.1"
4
+ end
data/memtar.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'memtar/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "memtar"
8
+ spec.version = MemTar::VERSION
9
+ spec.authors = ["Rafał Rzepecki"]
10
+ spec.email = ["rafal@conjur.net"]
11
+ spec.summary = %q{In-memory tar archive creation}
12
+ spec.homepage = "https://github.com/dividedmind/memtar"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_dependency "minitar", "~> 0.5"
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.7"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "rspec", "~> 3.2"
25
+ end
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+
3
+ require 'tempfile'
4
+
5
+ require 'memtar'
6
+
7
+ describe MemTar do
8
+ include SpecHelpers
9
+
10
+ describe '#add_file' do
11
+ it 'adds a file to the archive' do
12
+ subject.add_file 'some-file', 'foo', mode: 0600, uname: 'nobody'
13
+ has_file 'some-file', content: 'foo', mode: 0600, uname: 'nobody'
14
+ end
15
+
16
+ it 'handles File arguments' do
17
+ file = Tempfile.new 'foo'
18
+ file.chmod 0750
19
+ file.write 'bar'
20
+ file.close
21
+
22
+ subject.add_file 'xyzzy', File.new(file.path)
23
+ has_file 'xyzzy', content: 'bar', mode: 0750, uname: Etc.getlogin
24
+ file.unlink
25
+ end
26
+ end
27
+
28
+ describe '#add_symlink' do
29
+ it 'creates a symlink in the archive' do
30
+ subject.add_symlink 'password-file', '/etc/passwd'
31
+ has_symlink 'password-file'
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,49 @@
1
+ module SpecHelpers
2
+ def reader
3
+ @reader ||= Archive::Tar::Minitar::Reader.new StringIO.new subject.to_s
4
+ end
5
+
6
+ module TarEntryWithContent
7
+ attr_reader :content
8
+
9
+ def self.extended entry
10
+ entry.read
11
+ end
12
+
13
+ def read
14
+ @content ||= super
15
+ end
16
+ end
17
+
18
+ # Disregard spurious :reek:ControlParameter
19
+ def seek path
20
+ reader.rewind
21
+ reader.each do |entry|
22
+ return entry.extend TarEntryWithContent if entry.full_name == path
23
+ end
24
+ end
25
+
26
+ def has_file path, opts
27
+ file = seek path
28
+
29
+ expect(file).to be
30
+
31
+ opts.each do |key, value|
32
+ expect(file.send key).to eq value
33
+ end
34
+
35
+ file
36
+ end
37
+
38
+ def has_symlink path
39
+ file = seek path
40
+
41
+ expect(file).to be
42
+ expect(file.typeflag).to eq '2'
43
+
44
+ # linkname reading is broken in minitar
45
+ # expect(file.linkname).to eq target
46
+
47
+ file
48
+ end
49
+ end
metadata ADDED
@@ -0,0 +1,113 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: memtar
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Rafał Rzepecki
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-02-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: minitar
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.5'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.7'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.2'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.2'
69
+ description:
70
+ email:
71
+ - rafal@conjur.net
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".overcommit.yml"
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - lib/memtar.rb
83
+ - lib/memtar/version.rb
84
+ - memtar.gemspec
85
+ - spec/memtar_spec.rb
86
+ - spec/spec_helper.rb
87
+ homepage: https://github.com/dividedmind/memtar
88
+ licenses:
89
+ - MIT
90
+ metadata: {}
91
+ post_install_message:
92
+ rdoc_options: []
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ requirements: []
106
+ rubyforge_project:
107
+ rubygems_version: 2.4.4
108
+ signing_key:
109
+ specification_version: 4
110
+ summary: In-memory tar archive creation
111
+ test_files:
112
+ - spec/memtar_spec.rb
113
+ - spec/spec_helper.rb