API:EPrints/DataObj/File

From EPrints Documentation
Revision as of 15:26, 16 December 2011 by Tdb01r (talk | contribs)
Jump to: navigation, search

EPrints 3 Reference: Directory Structure - Metadata Fields - Repository Configuration - XML Config Files - XML Export Format - EPrints data structure - Core API - Data Objects


API: Core API

Latest Source Code (3.4, 3.3) | Revision Log | Before editing this page please read Pod2Wiki


NAME

EPrints::DataObj::File - a stored file

User Comments


DESCRIPTION

This class contains the technical metadata associated with a file. A file is a sequence of bytes stored in the storage layer (a "stored object"). Utility methods for storing and retrieving the stored object from the storage layer are made available.

Revision numbers on File work slightly differently to other objects. A File is only revised when it's stored object is changed and not when changes to it's metadata are made.

This class is a subclass of EPrints::DataObj::SubObject.

User Comments


CORE FIELDS

User Comments


fileid

Unique identifier for this file.

User Comments


rev_number (int)

The number of the current revision of this file.

User Comments


datasetid

Id of the dataset of the parent object.

User Comments


objectid

Id of the parent object.

User Comments


filename

Name of the file (may contain directory separators).

User Comments


mime_type

MIME type of the file (e.g. "image/png").

User Comments


hash

Check sum of the file.

User Comments


hash_type

Name of check sum algorithm used (e.g. "MD5").

User Comments


filesize

Size of the file in bytes.

User Comments


mtime

Last modification time of the file.

User Comments


url

Virtual field for storing the file's URL.

User Comments


data

Virtual field for storing the file's content.

User Comments


METHODS

User Comments


Constructor Methods

User Comments


new_from_filename

$dataobj = EPrints::DataObj::File->new_from_filename( $session, $dataobj, $filename )

Convenience method to get an existing File object for $filename stored in $dataobj.

Returns undef if no such record exists.

User Comments


create_from_data

$dataobj = EPrints::DataObj::File->create_from_data( $session, $data [, $dataset ] )

Create a new File record using $data.

Private data elements:

 _content - content to pass to set_file.
 _filepath - path to source file used for improved mime-type detection
 

User Comments


Class Methods

User Comments


get_system_field_info

$thing = EPrints::DataObj::File->get_system_field_info

Core fields.

User Comments


get_dataset_id

$dataset = EPrints::DataObj::File->get_dataset_id

Returns the id of the EPrints::DataSet object to which this record belongs.

User Comments


Object Methods

User Comments


clone

$new_file = $file->clone( $parent )

Clone the $file object (including contained files) and return the new object.

User Comments


remove

$success = $file->remove

Delete the stored file.

User Comments


get_local_copy

$filename = $file->get_local_copy()

Return the name of a local copy of the file (may be a File::Temp object).

Will retrieve and cache the remote object if necessary.

User Comments


add_file

$success = $file->add_file( $filepath, $filename [, $preserve_path ] )

Read and store the contents of $filepath at $filename.

If $preserve_path is untrue will strip any leading path in $filename.

User Comments


upload

$bytes = $file->upload( $filehandle, $filename, $filesize [, $preserve_path ] )

Read and store the data from $filehandle at $filename at the next revision number.

If $preserve_path is untrue will strip any leading path in $filename.

Returns the number of bytes read from $filehandle or undef on failure.

User Comments


write_copy

$success = $stored->write_copy( $filename )

Write a copy of this file to $filename.

Returns true if the written file contains the same number of bytes as the stored file.

User Comments


write_copy_fh

$success = $stored->write_copy_fh( $filehandle )

Write a copy of this file to $filehandle.

User Comments


generate_md5

$md5 = $stored->generate_md5

Calculates and returns the MD5 for this file.

User Comments


generate_sha

$digest = $file->generate_sha( [ ALGORITHM ] )

Generate a SHA for this file, see Digest::SHA::PurePerl for a list of supported algorithms. Defaults to "256" (SHA-256).

Returns the hex-encoded digest.

User Comments


add_plugin_copy

$stored->add_plugin_copy( $plugin, $sourceid )

Add a copy of this file stored using $plugin identified by $sourceid.

User Comments


remove_plugin_copy

$stored->remove_plugin_copy( $plugin )

Remove the copy of this file stored using $plugin.

User Comments


get_file

$success = $stored->get_file( CALLBACK [, $offset, $n ] )

Get the contents of the stored file - see EPrints::Storage/retrieve.

$offset is the position in bytes to start reading from, default 0.

$n is the number of bytes to read, default filesize.

User Comments


set_file

$content_length = $stored->set_file( CONTENT, $content_length )

Reads data from CONTENT and stores it. Sets the MD5 hash and filesize.

If the write failed returns undef and sets the filesize to 0.

CONTENT may be one of:

 CODEREF - will be called until it returns empty string ("")
 SCALARREF - a scalar reference will be used as-is (expects bytes)
 GLOB - will be treated as a file handle and read with sysread()
 

This method does not check the actual number of bytes read is the same as $content_length.

User Comments


SEE ALSO

EPrints::DataObj and EPrints::DataSet.

User Comments


COPYRIGHT

User Comments