Class: Webgen::Source::TarArchive
- Inherits:
-
Object
- Object
- Webgen::Source::TarArchive
- Defined in:
- lib/webgen/source/tararchive.rb
Overview
This class is used to read source paths from a (gzipped) tar archive. The archive can be remote (http(s) or ftp) or local.
For example, the following are all valid URIs:
http://example.com/directory/file.tgz
/home/test/my.tar.gz
ftp://ftp.example.com/archives/archive.tar
Defined Under Namespace
Classes: Path
Instance Attribute Summary collapse
-
#glob ⇒ Object
readonly
The glob (see File.fnmatch for details) that is used to specify which paths in the archive should be returned by #paths.
-
#uri ⇒ Object
readonly
The URI of the tar archive.
Instance Method Summary collapse
-
#initialize(uri, glob = '**/*') ⇒ TarArchive
constructor
Create a new tar archive source for the URI string
uri
. -
#paths ⇒ Object
Return all paths in the tar archive available at #uri.
Constructor Details
#initialize(uri, glob = '**/*') ⇒ TarArchive
Create a new tar archive source for the URI string uri
.
49 50 51 52 |
# File 'lib/webgen/source/tararchive.rb', line 49 def initialize(uri, glob = '**/*') @uri = uri @glob = glob end |
Instance Attribute Details
#glob ⇒ Object (readonly)
The glob (see File.fnmatch for details) that is used to specify which paths in the archive should be returned by #paths.
46 47 48 |
# File 'lib/webgen/source/tararchive.rb', line 46 def glob @glob end |
#uri ⇒ Object (readonly)
The URI of the tar archive.
42 43 44 |
# File 'lib/webgen/source/tararchive.rb', line 42 def uri @uri end |
Instance Method Details
#paths ⇒ Object
Return all paths in the tar archive available at #uri.
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/webgen/source/tararchive.rb', line 55 def paths if !defined?(@paths) stream = open(@uri) stream = Zlib::GzipReader.new(stream) if @uri =~ /(\.tar\.gz|\.tgz)$/ Archive::Tar::Minitar::Input.open(stream) do |input| @paths = input.collect do |entry| path = entry.full_name next unless File.fnmatch(@glob, path, File::FNM_DOTMATCH|File::FNM_CASEFOLD|File::FNM_PATHNAME) path += '/' if entry.directory? && path[-1] != ?/ Path.new(path, entry.read, Time.at(entry.mtime), @uri) end.compact.to_set end end @paths end |