Archive-Ar

 view release on metacpan or  search on metacpan

lib/Archive/Ar.pm  view on Meta::CPAN

=head2 contains_file

  $bool = $ar->contains_file($filename)

Returns true if the archive contains a file with $filename.  Returns
undef otherwise.

=head2 extract

  $ar->extract()
  $ar->extract_file($filename)

Extracts files from the archive.  The first form extracts all files, the
latter extracts just the named file.  Extracted files are assigned the
permissions and modification time stored in the archive, and, if possible,
the user and group ownership.  Returns non-zero upon success, or undef if
failure.

=head2 rename

  $ar->rename($filename, $newname)

Changes the name of a file in the in-memory archive.

=head2 chmod

  $ar->chmod($filename, $mode);

Change the mode of the member to C<$mode>.

=head2 chown

  $ar->chown($filename, $uid, $gid);
  $ar->chown($filename, $uid);

Change the ownership of the member to user id C<$uid> and (optionally)
group id C<$gid>.  Negative id values are ignored.

=head2 remove

  $ar->remove(@filenames)
  $ar->remove($arrayref)

Removes files from the in-memory archive.  Returns the number of files
removed.

=head2 list_files

  @filenames = $ar->list_files()

Returns a list of the names of all the files in the archive.
If called in a scalar context, returns a reference to an array.

=head2 add_files

  $ar->add_files(@filenames)
  $ar->add_files($arrayref)

Adds files to the archive.  The arguments can be paths, but only the
filenames are stored in the archive.  Stores the uid, gid, mode, size,
and modification timestamp of the file as returned by C<stat()>.

Returns the number of files successfully added, or undef if failure.

=head2 add_data

  $ar->add_data("filename", $data)
  $ar->add_data("filename", $data, $options)

Adds a file to the in-memory archive with name $filename and content
$data.  File properties can be set with $optional_hashref:

  $options = {
      'data' => $data,
      'uid' => $uid,    #defaults to zero
      'gid' => $gid,    #defaults to zero
      'date' => $date,  #date in epoch seconds. Defaults to now.
      'mode' => $mode,  #defaults to 0100644;
  }

You cannot add_data over another file however.  This returns the file length in 
bytes if it is successful, undef otherwise.

=head2 write

  $data = $ar->write()
  $len = $ar->write($filename)

Returns the archive as a string, or writes it to disk as $filename.
Returns the archive size upon success when writing to disk.  Returns
undef if failure.

=head2 get_content

  $content = $ar->get_content($filename)

This returns a hash with the file content in it, including the data
that the file would contain.  If the file does not exist or no filename
is given, this returns undef. On success, a hash is returned:

    $content = {
        'name' => $filename,
        'date' => $mtime,
        'uid' => $uid,
        'gid' => $gid,
        'mode' => $mode,
        'size' => $size,
        'data' => $file_contents,
    }

=head2 get_data

  $data = $ar->get_data("filename")

Returns a scalar containing the file data of the given archive
member.  Upon error, returns undef.

=head2 get_handle

  $handle = $ar->get_handle("filename")>



( run in 2.225 seconds using v1.01-cache-2.11-cpan-fe3c2283af0 )