1 #ifndef HUGE_FILE_CLASS
2 #define HUGE_FILE_CLASS
4 /*****************************************************************************\
7 * Author : Chris Koeritz *
9 *******************************************************************************
10 * Copyright (c) 2007-$now By Author. This program is free software; you can *
11 * redistribute it and/or modify it under the terms of the GNU General Public *
12 * License as published by the Free Software Foundation; either version 2 of *
13 * the License or (at your option) any later version. This is online at: *
14 * http://www.fsf.org/copyleft/gpl.html *
15 * Please send any updates to: fred@gruntose.com *
16 \*****************************************************************************/
18 #include "byte_filer.h"
20 #include <basis/astring.h>
21 #include <basis/outcome.h>
22 #include <basis/common_outcomes.h>
23 #include <basis/enhance_cpp.h>
25 namespace filesystem {
27 //! Supports reading and writing to very large files, > 4 gigabytes.
29 The standard file I/O functions only handle files up to 4 gigabytes. This
30 class extends the range to essentially unlimited sizes, as long as the
31 operating system can accurately do relative seeks and can read/write to
32 files of the size needed.
38 huge_file(const basis::astring &filename, const basis::astring &permissions);
39 //!< opens "filename" for access, where it presumably is a very large file.
40 /*!< see byte filer for a description of the permissions.
44 DEFINE_CLASS_NAME("huge_file");
47 OKAY = basis::common::OKAY,
48 FAILURE = basis::common::FAILURE,
49 ACCESS_DENIED = basis::common::ACCESS_DENIED,
50 BAD_INPUT = basis::common::BAD_INPUT
54 //!< reports if the file was opened successfully.
57 //!< reports when the file pointer has reached the end of the file.
60 //!< expensive operation accesses the file to find length.
62 double file_pointer() const { return _file_pointer; }
63 //!< returns where we currently are in the file.
65 basis::outcome seek(double new_position,
66 byte_filer::origins origin = byte_filer::FROM_CURRENT);
67 //!< move the file pointer to "new_position" if possible.
68 /*!< the relative seek is the easiest type of seek to accomplish with a
69 huge file. the other types are also supported, but take a bit more to
72 basis::outcome move_to(double absolute_posn);
73 //!< simpler seek just goes from current location to "absolute_posn".
75 basis::outcome read(basis::byte_array &to_fill, int desired_size, int &size_read);
76 //!< reads "desired_size" into "to_fill" if possible.
77 /*!< "size_read" reports how many bytes were actually read. */
79 basis::outcome write(const basis::byte_array &to_write, int &size_written);
80 //!< stores the array "to_write" into the file.
81 /*!< "size_written" reports how many bytes got written. */
84 //!< truncates the file after the current position.
86 basis::outcome touch();
87 //<! creates the file if it doesn't exist, or updates the time on the file.
90 //!< forces any pending writes to actually be saved to the file.
93 byte_filer *_real_file; //!< supports us but is subject to 4g limit.
94 double _file_pointer; //!< position in the file if OS is tracking us.