Class: Distillery::Archiver::Archive

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/distillery/archiver/archive.rb

Overview

Allow archive file processing

All the operations are forwarded to an Distillery::Archiver instance which is able to process the selected archive file.

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ Archive

Returns a new instance of Archive.

Parameters:

  • file (String)

    file holding the archive

Raises:

  • (ArchiverNotFound)

    an archiver able to process this file has not been found



21
22
23
24
25
26
27
28
# File 'lib/distillery/archiver/archive.rb', line 21

def initialize(file)
    @file     = file
    @archiver = Archiver.for_file(file)

    if @archiver.nil?
        raise ArchiverNotFound, "no archiver avalaible for this file"
    end
end

Instance Method Details

#delete!(entry) ⇒ Boolean

Delete the entry from the archive

Parameters:

  • entry (String)

    entry name

Returns:

  • (Boolean)

    operation status



94
95
96
# File 'lib/distillery/archiver/archive.rb', line 94

def delete!(entry)
    @archiver.delete!(@file, entry)
end

#each {|entry, io| ... } ⇒ self, Enumerator

Iterate over each archive entry

Yield Parameters:

  • entry (String)

    entry name

  • io (InputStream)

    input stream

Returns:

  • (self, Enumerator)


38
39
40
41
# File 'lib/distillery/archiver/archive.rb', line 38

def each(&block)
    @archiver.each(@file, &block)
    self
end

#empty?Boolean

Is the archive emtpy?

Returns:

  • (Boolean)


57
58
59
# File 'lib/distillery/archiver/archive.rb', line 57

def empty?
    @archiver.empty?(@file)
end

#entriesArray<String>

List of entries for the archive

Returns:

  • (Array<String>)


48
49
50
# File 'lib/distillery/archiver/archive.rb', line 48

def entries
    @archiver.entries(@file)
end

#reader(entry) {|io| ... } ⇒ Object

Allow to perform read operation on an archive entry

Parameters:

  • entry (String)

    entry name

Yield Parameters:

Returns:

  • block value



70
71
72
# File 'lib/distillery/archiver/archive.rb', line 70

def reader(entry, &block)
    @archiver.reader(@file, entry, &block)
end

#writer(entry) {|io| ... } ⇒ Object

Allow to perform write operation on an archive entry

Parameters:

  • entry (String)

    entry name

Yield Parameters:

Returns:

  • block value



83
84
85
# File 'lib/distillery/archiver/archive.rb', line 83

def writer(entry, &block)
    @archiver.writer(@file, entry, &block)
end