class DPN::Bagit::SerializedBag
A wrapper for a serialized Bag-It bag on disk. Once created, will not change with changes made to the underlying filesystem bag; in that case, a new object should be created. @!attribute [r] location
@return [String] The location, which can be relative or absolute.
Attributes
Public Class Methods
Create a SerializedBag
@param path [String] Path to the file.
# File lib/dpn/bagit/serialized_bag.rb, line 15 def initialize(path) raise ArgumentError, "File does not exist!" unless File.exist?(path) @location = path end
Public Instance Methods
Returns the fixity of the serialized version of the bag. @param algorithm [Symbol] The algorithm to use for calculation. @return [String] fixity
# File lib/dpn/bagit/serialized_bag.rb, line 41 def fixity(algorithm) @cachedFixity ||= begin case algorithm when :sha256 digest = Digest::SHA256 else raise ArgumentError, "Unknown algorithm." end digest.file(location).hexdigest end end
Returns the file name for the serialized bag, without it's extension. @return [String] name
# File lib/dpn/bagit/serialized_bag.rb, line 22 def name @name ||= File.basename(location, File.extname(location)) end
Returns the directory path to the serialized bag. @return [String] path
# File lib/dpn/bagit/serialized_bag.rb, line 28 def path @path ||= File.dirname(location) end
Returns the size of the serialized bag (in bytes). @return [Fixnum] size
# File lib/dpn/bagit/serialized_bag.rb, line 34 def size File.size(location) end
Unserialize the bag into the local filesystem. This object is unchanged. Requires sufficient permissions and disk space. @return [DPN::Bagit::Bag] A bag made from the unserialized object.
# File lib/dpn/bagit/serialized_bag.rb, line 56 def unserialize! `/bin/tar -xf #{location} -C #{path} 2> /dev/null` raise RuntimeError, "cannot untar #{location}" unless $?.success? DPN::Bagit::Bag.new(File.join(path, name)) end