Class: WinRM::FS::Core::TmpZip

Inherits:
Object
  • Object
show all
Defined in:
lib/winrm-fs/core/tmp_zip.rb

Overview

A temporary Zip file for a given directory.

Author:

Defined Under Namespace

Classes: NoDupIO

Instance Method Summary collapse

Constructor Details

#initialize(dir, logger = nil) ⇒ TmpZip

Contructs a new Zip file for the given directory.

There are 2 ways to interpret the directory path:

  • If the directory has no path separator terminator, then the directory basename will be used as the base directory in the resulting zip file.

  • If the directory has a path separator terminator (such as ‘/` or `\`), then the entries under the directory will be added to the resulting zip file.

The following emaples assume a directory tree structure of:

src
|-- alpha.txt
|-- beta.txt
\-- sub
    \-- charlie.txt

Examples:

Including the base directory in the zip file


TmpZip.new("/path/to/src")
# produces a zip file with entries:
# - src/alpha.txt
# - src/beta.txt
# - src/sub/charlie.txt

Excluding the base directory in the zip file


TmpZip.new("/path/to/src/")
# produces a zip file with entries:
# - alpha.txt
# - beta.txt
# - sub/charlie.txt

Parameters:

  • dir (String, Pathname, #to_s)

    path to the directory

  • logger (#debug, #debug?) (defaults to: nil)

    an optional logger/ui object that responds to ‘#debug` and `#debug?` (default `nil`)



70
71
72
73
74
75
76
# File 'lib/winrm-fs/core/tmp_zip.rb', line 70

def initialize(dir, logger = nil)
  @logger = logger || Logging.logger[self]
  @dir = clean_dirname(dir)
  @zip_io = Tempfile.open(['tmpzip-', '.zip'], binmode: true)
  write_zip
  @zip_io.close
end

Instance Method Details

#pathPathname

Returns path to zip file.

Returns:

  • (Pathname)

    path to zip file



79
80
81
# File 'lib/winrm-fs/core/tmp_zip.rb', line 79

def path
  Pathname.new(zip_io.path) if zip_io.path
end

Unlinks (deletes) the zip file from the filesystem.



84
85
86
# File 'lib/winrm-fs/core/tmp_zip.rb', line 84

def unlink
  zip_io.unlink
end