Class: WinRM::Transport::TmpZip

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/winrm/transport/tmp_zip.rb

Overview

A temporary Zip file for a given directory.

Author:

Defined Under Namespace

Classes: NoDupIO

Instance Method Summary collapse

Methods included from Logging

#debug

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`)



75
76
77
78
79
80
81
82
83
# File 'lib/winrm/transport/tmp_zip.rb', line 75

def initialize(dir, logger = nil)
  @logger = logger
  @dir = Pathname.new(dir)
  @method = ::Zip::Entry::DEFLATED
  @compression = Zlib::BEST_COMPRESSION
  @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



86
87
88
# File 'lib/winrm/transport/tmp_zip.rb', line 86

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

Unlinks (deletes) the zip file from the filesystem.



91
92
93
# File 'lib/winrm/transport/tmp_zip.rb', line 91

def unlink
  zip_io.unlink
end