Class: Gitlab::Ci::Build::Artifacts::Adapters::GzipStream

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/ci/build/artifacts/adapters/gzip_stream.rb

Constant Summary collapse

InvalidStreamError =
Class.new(StandardError)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(stream) ⇒ GzipStream

Returns a new instance of GzipStream.

Raises:



13
14
15
16
17
# File 'lib/gitlab/ci/build/artifacts/adapters/gzip_stream.rb', line 13

def initialize(stream)
  raise InvalidStreamError, "Stream is required" unless stream

  @stream = stream
end

Instance Attribute Details

#streamObject (readonly)

Returns the value of attribute stream.



9
10
11
# File 'lib/gitlab/ci/build/artifacts/adapters/gzip_stream.rb', line 9

def stream
  @stream
end

Instance Method Details

#each_blobObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/gitlab/ci/build/artifacts/adapters/gzip_stream.rb', line 19

def each_blob
  stream.seek(0)

  until stream.eof?
    gzip(stream) do |gz|
      yield gz.read, gz.orig_name
      unused = gz.unused&.length.to_i
      # pos has already reached to EOF at the moment
      # We rewind the pos to the top of unused files
      # to read next gzip stream, to support multistream archives
      # https://golang.org/src/compress/gzip/gunzip.go#L117
      stream.seek(-unused, IO::SEEK_CUR)
    end
  end
end