Turi Create  4.0
turi::dir_archive Class Reference

#include <core/storage/serialization/dir_archive.hpp>

Public Member Functions

 ~dir_archive ()
 
void open_directory_for_write (std::string directory, bool fail_on_existing=false)
 
void open_directory_for_read (std::string directory)
 
std::string get_directory () const
 
std::string get_next_write_prefix ()
 
std::string get_next_read_prefix ()
 
general_ifstreamget_input_stream ()
 
general_ofstreamget_output_stream ()
 
void close ()
 
void set_metadata (std::string key, std::string val)
 
bool get_metadata (std::string key, std::string &val) const
 

Static Public Member Functions

static void delete_archive (std::string directory)
 
static bool directory_has_existing_archive (const std::vector< std::pair< std::string, fileio::file_status > > &dircontents)
 

Detailed Description

The dir_archive object manages a directory archive. It is an internal class which provides two basic containers:

  • A single file stream object (a general_ifstream / general_ofstream) which points to an "objects.bin" file in the directory.
  • The ability to obtain prefixes (for instance [directory]/0000) which consumers can then use for other file storage purposes. (for instance, an sframe could create 0000.sidx, 0000.0001, 0000.0002, etc),

The directory archive provide management for the prefixes and the objects as well as directory archive creation / deletion.

To use:

dir_archive archive;
archive.open_directory_for_write(dir)
oarchive oarc(archive)
oarc << ...
oarc.get_prefix()
etc.

Similarly, to read:

dir_archive archive;
archive.open_directory_for_read(dir)
iarchive iarc(archive)
iarc >> ...
iarc.get_prefix()
etc.

Definition at line 96 of file dir_archive.hpp.

Constructor & Destructor Documentation

◆ ~dir_archive()

turi::dir_archive::~dir_archive ( )

Destructor. Also closes.

Member Function Documentation

◆ close()

void turi::dir_archive::close ( )

Closes the directory archive, committing all writes.

◆ delete_archive()

static void turi::dir_archive::delete_archive ( std::string  directory)
static

Deletes the contents of an archive safely. (i.e. performing a non-recursive delete so we don't ever, even by accident, delete stuff we are not meant to delete).

It will delete the directory the archive is in if the directory is empty after deletion of all the archive files.

Never throws.

◆ directory_has_existing_archive()

static bool turi::dir_archive::directory_has_existing_archive ( const std::vector< std::pair< std::string, fileio::file_status > > &  dircontents)
static

Returns true if the directory contains an archive

◆ get_directory()

std::string turi::dir_archive::get_directory ( ) const

Returns the current directory opened by either open_directory_for_read() or open_directory_for_write(); if nothing is opened, this returns an empty string.

◆ get_input_stream()

general_ifstream* turi::dir_archive::get_input_stream ( )

Returns a pointer to the object stream reader. Returns NULL if the input directory is not opened for read.

◆ get_metadata()

bool turi::dir_archive::get_metadata ( std::string  key,
std::string &  val 
) const

Reads any metadata associated with the archive. Returns true if the key exists, false otherwise.

◆ get_next_read_prefix()

std::string turi::dir_archive::get_next_read_prefix ( )

The directory must be opened for read. This returns the next prefix in the sequence of generated prefixes. The order of prefixes returns is the same order as the prefixes generated by get_next_write_prefix() when the archive was created.

◆ get_next_write_prefix()

std::string turi::dir_archive::get_next_write_prefix ( )

The directory must be opened for write. This returns a new prefix which can be written to.

◆ get_output_stream()

general_ofstream* turi::dir_archive::get_output_stream ( )

Returns a pointer to the object stream writer. Returns NULL if the input directory is not opened for write.

◆ open_directory_for_read()

void turi::dir_archive::open_directory_for_read ( std::string  directory)

Opens a directory for reading. Directory must be an absolute path. This function will fail if the directory is not an archive.

Throws an exception with a string message if the directory cannot be opened.

◆ open_directory_for_write()

void turi::dir_archive::open_directory_for_write ( std::string  directory,
bool  fail_on_existing = false 
)

Opens a directory for writing. Directory must be an absolute path.

if fail_on_existing is false: (default)

  • This function will only fail if the directory exists, and does not contain an archive. It will overwrite in all other cases.

if fail_on_existing is true:

  • The function will fail if the the directory points to a file name.
  • The function will fail if the the directory exists.

Throws an exception with a string message if the directory cannot be opened.

◆ set_metadata()

void turi::dir_archive::set_metadata ( std::string  key,
std::string  val 
)

Associates additional metadata with the archive that can be read back with get_metadata() when it is loaded.


The documentation for this class was generated from the following file: