27 #define DEBUG_FILE_INFO
31 #define LOG(to_print) printf("%s::%s: %s\n", static_class_name(), func, astring(to_print).s())
33 using namespace basis;
38 file_info::file_info()
50 _file_size(file_size),
59 _file_size(to_copy._file_size),
61 _checksum(to_copy._checksum),
62 c_secondary(to_copy.c_secondary),
63 c_attachment(to_copy.c_attachment)
72 { c_attachment = new_attachment; }
83 to_return +=
astring(
", 2ndary=") + c_secondary;
91 if (prefix.
t()) full = prefix +
"/" + *
this;
94 #ifdef DEBUG_FILE_INFO
110 if (!to_read.
good()) {
111 #ifdef DEBUG_FILE_INFO
134 bool skip_tail =
false;
135 double head_start = 0, head_end = 0, tail_start = 0,
140 }
else if (
_file_size <=
double(2 * checksum_edge)) {
154 outcome ret = to_read.
read(chunk,
int(head_end - head_start + 1), size_read);
156 #ifdef DEBUG_FILE_INFO
161 curr_sum = checksums::rolling_fletcher_checksum(curr_sum, chunk.
observe(),
167 ret = to_read.
read(chunk,
int(tail_end - tail_start + 1), size_read);
169 #ifdef DEBUG_FILE_INFO
174 curr_sum = checksums::rolling_fletcher_checksum(curr_sum, chunk.
observe(),
199 c_secondary.
pack(packed_form);
200 attach(packed_form, c_attachment);
213 if (!c_secondary.
unpack(packed_form))
215 if (!
detach(packed_form, c_attachment))
222 if (
this == &to_copy)
225 c_attachment = to_copy.c_attachment;
228 c_secondary = to_copy.c_secondary;
a_sprintf is a specialization of astring that provides printf style support.
const contents * observe() const
Returns a pointer to the underlying C array of data.
int length() const
Returns the current reported length of the allocated C array.
Provides a dynamically resizable ASCII character string.
bool t() const
t() is a shortcut for the string being "true", as in non-empty.
void pack(byte_array &target) const
stores this string in the "target". it can later be unpacked again.
int packed_size() const
Reports the size required to pack this string into a byte array.
astring()
constructs an empty string.
bool unpack(byte_array &source)
retrieves a string (packed with pack()) from "source" into this string.
A very common template for a dynamic array of bytes.
Outcomes describe the state of completion for an operation.
@ FROM_START
offset is from the beginning of the file.
Encapsulates some measures and calculations based on a file's contents.
double _file_size
the size of the file.
file_info()
blank constructor.
virtual void pack(basis::byte_array &packed_form) const
Creates a packed form of the packable object in "packed_form".
const basis::astring & secondary() const
observes the alternate form of the name.
int _checksum
the checksum for the file.
file_time _time
the file's access time.
bool calculate(const basis::astring &prefix, bool just_size_n_time, int checksum_edge=1 *basis::KILOBYTE)
fills in the correct file size and checksum information for this file.
basis::astring text_form() const
virtual bool unpack(basis::byte_array &packed_form)
Restores the packable from the "packed_form".
virtual int packed_size() const
Estimates the space needed for the packed structure.
file_info & operator=(const file_info &to_copy)
const basis::byte_array & attachment() const
returns the chunk of data optionally attached to the file's info.
virtual int packed_size() const
virtual void pack(basis::byte_array &packed_form) const
virtual bool unpack(basis::byte_array &packed_form)
Provides operations commonly needed on file names.
bool exists() const
returns true if the file exists.
virtual bool unpack(basis::byte_array &packed_form)
Restores the packable from the "packed_form".
virtual void pack(basis::byte_array &packed_form) const
Creates a packed form of the packable object in "packed_form".
const basis::astring & raw() const
returns the astring that we're holding onto for the path.
virtual int packed_size() const
Estimates the space needed for the packed structure.
Supports reading and writing to very large files, > 4 gigabytes.
double length()
expensive operation accesses the file to find length.
basis::outcome seek(double new_position, byte_filer::origins origin=byte_filer::FROM_CURRENT)
move the file pointer to "new_position" if possible.
bool good() const
reports if the file was opened successfully.
basis::outcome read(basis::byte_array &to_fill, int desired_size, int &size_read)
reads "desired_size" into "to_fill" if possible.
#define FUNCDEF(func_in)
FUNCDEF sets the name of a function (and plugs it into the callstack).
The guards collection helps in testing preconditions and reporting errors.
void attach(byte_array &packed_form, const char *to_attach)
Packs a character string "to_attach" into "packed_form".
bool detach(byte_array &packed_form, astring &to_detach)
Unpacks a character string "to_attach" from "packed_form".
type minimum(type a, type b)
maximum returns the greater of two values.
A platform independent way to obtain the timestamp of a file.
A dynamic container class that holds any kind of object via pointers.
const int PACKED_SIZE_INT32
int packed_size(const byte_array &packed_form)
Reports the size required to pack a byte array into a byte array.