TarFileWriter.h (muscle7.61) | : | TarFileWriter.h (muscle7.62) | ||
---|---|---|---|---|
skipping to change at line 32 | skipping to change at line 32 | |||
/** Constructor. | /** Constructor. | |||
* @param outputFileName Name/path of the .tar file to write to | * @param outputFileName Name/path of the .tar file to write to | |||
* @param append If true, written data will be appended to this file; otherw ise | * @param append If true, written data will be appended to this file; otherw ise | |||
* if the file already exists it will be deleted and replaced. | * if the file already exists it will be deleted and replaced. | |||
* This constructor is equivalent to the default constructor, plus calling S etFile(). | * This constructor is equivalent to the default constructor, plus calling S etFile(). | |||
*/ | */ | |||
TarFileWriter(const char * outputFileName, bool append); | TarFileWriter(const char * outputFileName, bool append); | |||
/** Constructor. | /** Constructor. | |||
* @param dio Reference to a SeekableDataIO to use to write data out. | * @param dio Reference to a DataIO object to use to write out the .tar file data. | |||
* This constructor is equivalent to the default constructor, plus calling S etFile(). | * This constructor is equivalent to the default constructor, plus calling S etFile(). | |||
*/ | */ | |||
TarFileWriter(const SeekableDataIORef & dio); | TarFileWriter(const DataIORef & dio); | |||
/** Destructor. */ | /** Destructor. */ | |||
~TarFileWriter(); | ~TarFileWriter(); | |||
/** Closes the current file (if any is open) and returns to the just-default- | /** Writes any pending updates to the .tar file (if necessary), then closes t | |||
constructed state. | he file (if one is open) | |||
* @returns B_NO_ERROR on success, or an error code if there was an error wr | * and returns this object to its basic just-default-constructed state. | |||
iting out header data. | * @returns B_NO_ERROR on success, or an error code if there was an error wr | |||
* Note that this method will always close the held file-handle, ev | iting out pending header-data changes. | |||
en if it returns an error-code. | * Note that this method will always unreference any held DataIO an | |||
d reset our state to default, even if it returns an error-code. | ||||
*/ | */ | |||
status_t Close(); | status_t Close(); | |||
/** Closes the currently open file (if any) and attempts to open the new one. | /** Unreferences the currently held DataIO (if any) and attempts to open the new .tar file for writing. | |||
* @param outputFileName Name/path of the .tar file to write to | * @param outputFileName Name/path of the .tar file to write to | |||
* @param append If true, new written data will be appended to the existing file; otherwise | * @param append If true, new written data will be appended to the existing file; otherwise | |||
* if the file already exists it will be deleted and replaced. | * if the file already exists it will be deleted and replaced. | |||
*/ | */ | |||
status_t SetFile(const char * outputFileName, bool append); | status_t SetFile(const char * outputFileName, bool append); | |||
/** Closes the currently open file (if any) and uses the specified DataIO ins tead. | /** Unreferences the currently held DataIO (if any) and uses the specified Da taIO instead. | |||
* @param dioRef Reference to The DataIORef to use to output .tar data to, o r a NULL Ref to close only. | * @param dioRef Reference to The DataIORef to use to output .tar data to, o r a NULL Ref to close only. | |||
* @note if (dioRef) isn't referencing a SeekableDataIORef, then you are req | ||||
uired to pass a valid/correct file-size | ||||
* arguments to WriteFileHeader(). If (dioRef) is referencing a Seeka | ||||
bleDataIORef, then the file-size argument | ||||
* can optionally passed in as 0, and the TarFileWriter will update th | ||||
e header-fields automatically based on how | ||||
* much file-data was actually written. | ||||
*/ | */ | |||
void SetFile(const SeekableDataIORef & dioRef); | void SetFile(const DataIORef & dioRef); | |||
/** Writes a .tar header fle-block with the given information. | /** Writes a .tar header fle-block with the given information. | |||
* @param fileName The name of the member file as it should be recorded insi de the .tar file. | * @param fileName The name of the member file as it should be recorded insi de the .tar file. | |||
* @param fileMode The file-mode bits that should be stored with this file. | * @param fileMode The file-mode bits that should be stored with this file. | |||
* @param ownerID The file's owner's numeric user ID | * @param ownerID The file's owner's numeric user ID | |||
* @param groupID The file's group's numeric user ID | * @param groupID The file's group's numeric user ID | |||
* @param modificationTime A timestamp indicating the file's last modificati on time (microseconds since 1970) | * @param modificationTime A timestamp indicating the file's last modificati on time (microseconds since 1970) | |||
* @param linkIndicator one of the TAR_LINK_INDICATOR_* values | * @param linkIndicator one of the TAR_LINK_INDICATOR_* values | |||
* @param linkedFileName Name of the linked file (if any); | * @param linkedFileName Name of the linked file (if any); | |||
* @param fileSize if you know the size of the file in advance, you can pass | ||||
in the file-size (in bytes) in this argument. | ||||
* Note that if the DataIORef object the TarFileWriter isn't | ||||
a SeekableDataIORef, then passing in the | ||||
* correct file size here is mandatory, as the TarFileWriter | ||||
will be unable to seek back and patch up | ||||
* the file-size header field later. OTOH if you are using | ||||
a SeekableDataIORef and don't know the file-size | ||||
* up-front, you can just pass in zero here. | ||||
* @returns B_NO_ERROR on success, or an error code on failure. | * @returns B_NO_ERROR on success, or an error code on failure. | |||
*/ | */ | |||
status_t WriteFileHeader(const char * fileName, uint32 fileMode, uint32 owner ID, uint32 groupID, uint64 modificationTime, int linkIndicator, const char * lin kedFileName); | status_t WriteFileHeader(const char * fileName, uint32 fileMode, uint32 owner ID, uint32 groupID, uint64 modificationTime, int linkIndicator, const char * lin kedFileName, uint64 fileSize); | |||
/** Writes (numBytes) of data into the current file block. | /** Writes (numBytes) of data into the currently active file-block. | |||
* Three must be a file-header currently active for this call to succeed. | * Three must be a file-header currently active for this call to succeed. | |||
* @param fileData Pointer to some data bytes to write into the tar file. | * @param fileData Pointer to some data bytes to write into the tar file. | |||
* @param numBytes How many bytes (fileData) points to. | * @param numBytes How many bytes (fileData) points to. | |||
* @returns B_NO_ERROR on success, or an error code on failure. | * @returns B_NO_ERROR on success, or an error code on failure. | |||
*/ | */ | |||
status_t WriteFileData(const uint8 * fileData, uint32 numBytes); | status_t WriteFileData(const uint8 * fileData, uint32 numBytes); | |||
/** Updates the current file-header-block and resets our state to receive the next one. | /** Updates the current file-header-block and resets our state to receive the next one. | |||
* Note that Close() and WriteFileHeader() will call FinishCurrentFileDataBl | * @returns B_NO_ERROR on success (or if no file-header-block was open), or | |||
ock() if necessary, so calling this method isn't strictly necessary. | an error code if there was an error updating the file-header-block. | |||
* @returns B_NO_ERROR on success (or if no header-block was open), or an er | * @note that Close() and WriteFileHeader() will call FinishCurrentFileDataB | |||
ror code if there was an error updating the header block. | lock() implicitly when necessary, so | |||
* calling this method isn't strictly necessary. | ||||
*/ | */ | |||
status_t FinishCurrentFileDataBlock(); | status_t FinishCurrentFileDataBlock(); | |||
/** These values may be passed to the (linkIndicator) argument of WriteFileHe ader() to indicate what kind of filesystem-object the header is describing. */ | /** These values may be passed to the (linkIndicator) argument of WriteFileHe ader() to indicate what kind of filesystem-object the header is describing. */ | |||
enum { | enum { | |||
TAR_LINK_INDICATOR_NORMAL_FILE = 0, /**< A normal data-file */ | TAR_LINK_INDICATOR_NORMAL_FILE = 0, /**< A normal data-file */ | |||
TAR_LINK_INDICATOR_HARD_LINK, /**< A hard-link */ | TAR_LINK_INDICATOR_HARD_LINK, /**< A hard-link */ | |||
TAR_LINK_INDICATOR_SYMBOLIC_LINK, /**< A symbolic link */ | TAR_LINK_INDICATOR_SYMBOLIC_LINK, /**< A symbolic link */ | |||
TAR_LINK_INDICATOR_CHARACTER_SPECIAL, /**< A file representing a characte r-based device */ | TAR_LINK_INDICATOR_CHARACTER_SPECIAL, /**< A file representing a characte r-based device */ | |||
TAR_LINK_INDICATOR_BLOCK_SPECIAL, /**< A file representing a block-ba sed device */ | TAR_LINK_INDICATOR_BLOCK_SPECIAL, /**< A file representing a block-ba sed device */ | |||
skipping to change at line 106 | skipping to change at line 117 | |||
/** Returns true iff we successfully opened the .tar output file. */ | /** Returns true iff we successfully opened the .tar output file. */ | |||
bool IsFileOpen() const {return (_writerIO() != NULL);} | bool IsFileOpen() const {return (_writerIO() != NULL);} | |||
/** Returns true iff we successfully started a .tar record block and it is cu rrently open. */ | /** Returns true iff we successfully started a .tar record block and it is cu rrently open. */ | |||
bool IsFileDataBlockOpen() const {return (_currentHeaderOffset >= 0);} | bool IsFileDataBlockOpen() const {return (_currentHeaderOffset >= 0);} | |||
private: | private: | |||
enum {TAR_BLOCK_SIZE=512}; | enum {TAR_BLOCK_SIZE=512}; | |||
int64 GetCurrentSeekPosition() const; | void UpdateCurrentHeaderChecksum(); | |||
SeekableDataIORef _writerIO; | DataIORef _writerIO; | |||
SeekableDataIORef _seekableWriterIO; // pre-downcast reference, for convenie | ||||
nce. Will be NULL if our DataIO isn't a SeekableDataIO! | ||||
int64 _currentHeaderOffset; | int64 _currentHeaderOffset; | |||
uint8 _currentHeaderBytes[TAR_BLOCK_SIZE]; | uint8 _currentHeaderBytes[TAR_BLOCK_SIZE]; | |||
uint64 _prestatedFileSize; // as passed in to WriteFileHeader() | ||||
uint64 _currentSeekPosition; // gotta track this manually since (_seekableWr | ||||
iterIO()) may be NULL) | ||||
}; | }; | |||
} // end namespace muscle | } // end namespace muscle | |||
#endif | #endif | |||
End of changes. 14 change blocks. | ||||
19 lines changed or deleted | 42 lines changed or added |