mini_tarball 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bb6115ef818ae567ea4efad8646977a26cbb62f5164e656bd8d403dd1775ff38
4
- data.tar.gz: 5364a6eece1aa623c4bb900eaf50de383017dcd4b9285f5f7b3b52423638d9b2
3
+ metadata.gz: e4f402eb6b43dd9a6a5b62d59d60d4ab949e9ea9c4e03be89354ab71624f5c74
4
+ data.tar.gz: 96e28996b32be3a777e7e8a1517e746536851e8a5e5cd330854a2e75b763be70
5
5
  SHA512:
6
- metadata.gz: d8978adda8f400f47d37d037fc439d6d803538910aaa97a78cee3ec111b34616c0b3acd298a6a5b406a02a8e0d698e25743a5a4ff32a2e1b827835892621d186
7
- data.tar.gz: 543abee46d1e1bd3df2abdd0b0164f2e72363d65ec63a7ac8c120302c94a0fc247315fcb7c4541774ab08ef00178e4de1df355cb2699e0056f0d984e53f532bc
6
+ metadata.gz: 0b941f8cb82d7a0a73782cd59e4e6185c4e28bd4c3e41f5eaaff1056e8503747df7012ba5cbe6a515d2138183bed3502f977b62f5cf6ab1909d9d7efdc3cd956
7
+ data.tar.gz: 108091d73b67d1cff944b04fc9c0123490b2234fcf1d53a53858bfa341204ab1bb7048b71cc4e596cb979c4ef92d62f0ebce6d914267f0012fe5e387477e7d40
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MiniTarball
4
+ class WriteOutOfRangeError < StandardError; end
5
+
6
+ class LimitedSizeStream
7
+ attr_reader :start_position, :end_position
8
+
9
+ def initialize(io, start_position:, max_file_size:)
10
+ @io = io
11
+ @start_position = start_position
12
+ @end_position = start_position + max_file_size
13
+ end
14
+
15
+ def write(data)
16
+ if @io.pos < start_position || @io.pos + data.bytesize > end_position
17
+ raise WriteOutOfRangeError.new("Writing outside of limits not allowed")
18
+ end
19
+
20
+ @io.write(data)
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MiniTarball
4
+ class PlaceholderStream < LimitedSizeStream
5
+ def initialize(io, start_position:, file_size:)
6
+ super(io, start_position: start_position, max_file_size: file_size)
7
+ end
8
+
9
+ def write(data)
10
+ super(data)
11
+ @io.write("\0" * (end_position - @io.pos)) if @io.pos <= end_position
12
+ end
13
+ end
14
+ end
@@ -7,7 +7,7 @@ module MiniTarball
7
7
  end
8
8
 
9
9
  def write(data)
10
- @io.write (data)
10
+ @io.write(data)
11
11
  end
12
12
  end
13
13
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MiniTarball
4
- VERSION = "0.2.0"
4
+ VERSION = "0.3.0"
5
5
  end
@@ -35,6 +35,7 @@ module MiniTarball
35
35
  @write_only_io = WriteOnlyStream.new(@io)
36
36
  @header_writer = HeaderWriter.new(@write_only_io)
37
37
  @closed = false
38
+ @placeholders = []
38
39
  end
39
40
 
40
41
  def add_file(name:, source_file_path:, mode: nil, uname: nil, gname: nil, uid: nil, gid: nil, mtime: nil)
@@ -86,6 +87,43 @@ module MiniTarball
86
87
  nil
87
88
  end
88
89
 
90
+ def add_file_placeholder(name:, file_size:)
91
+ ensure_not_closed!
92
+
93
+ placeholder = {}
94
+ placeholder[:header_start_position] = @io.pos
95
+ @header_writer.write(Header.new(name: name, size: file_size))
96
+
97
+ placeholder[:file_start_position] = @io.pos
98
+ @io.write("\0" * file_size)
99
+ placeholder[:file_size] = file_size
100
+
101
+ write_padding
102
+
103
+ @placeholders << placeholder
104
+ @placeholders.size - 1
105
+ end
106
+
107
+ def with_placeholder(index)
108
+ placeholder = @placeholders[index]
109
+ raise ArgumentError.new("Placeholder not found") if placeholder.nil?
110
+
111
+ @io.seek(placeholder[:header_start_position])
112
+ old_write_only_io = @write_only_io
113
+ @write_only_io = PlaceholderStream.new(
114
+ @io,
115
+ start_position: placeholder[:file_start_position],
116
+ file_size: placeholder[:file_size]
117
+ )
118
+
119
+ yield self
120
+
121
+ @write_only_io = old_write_only_io
122
+ @io.seek(0, IO::SEEK_END)
123
+
124
+ nil
125
+ end
126
+
89
127
  def closed?
90
128
  @closed
91
129
  end
data/lib/mini_tarball.rb CHANGED
@@ -3,6 +3,8 @@
3
3
  require 'mini_tarball/header'
4
4
  require 'mini_tarball/header_formatter'
5
5
  require 'mini_tarball/header_writer'
6
- require 'mini_tarball/write_only_stream'
6
+ require 'mini_tarball/streams/limited_size_stream'
7
+ require 'mini_tarball/streams/placeholder_stream'
8
+ require 'mini_tarball/streams/write_only_stream'
7
9
  require 'mini_tarball/writer'
8
10
  require 'mini_tarball/version'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mini_tarball
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Discourse
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-09 00:00:00.000000000 Z
11
+ date: 2022-10-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -105,8 +105,10 @@ files:
105
105
  - lib/mini_tarball/header.rb
106
106
  - lib/mini_tarball/header_formatter.rb
107
107
  - lib/mini_tarball/header_writer.rb
108
+ - lib/mini_tarball/streams/limited_size_stream.rb
109
+ - lib/mini_tarball/streams/placeholder_stream.rb
110
+ - lib/mini_tarball/streams/write_only_stream.rb
108
111
  - lib/mini_tarball/version.rb
109
- - lib/mini_tarball/write_only_stream.rb
110
112
  - lib/mini_tarball/writer.rb
111
113
  homepage: https://github.com/discourse/mini_tarball
112
114
  licenses:
@@ -122,14 +124,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
122
124
  requirements:
123
125
  - - ">="
124
126
  - !ruby/object:Gem::Version
125
- version: 2.6.0
127
+ version: 2.7.0
126
128
  required_rubygems_version: !ruby/object:Gem::Requirement
127
129
  requirements:
128
130
  - - ">="
129
131
  - !ruby/object:Gem::Version
130
132
  version: '0'
131
133
  requirements: []
132
- rubygems_version: 3.1.4
134
+ rubygems_version: 3.1.6
133
135
  signing_key:
134
136
  specification_version: 4
135
137
  summary: A minimal implementation of the GNU Tar format.