diff --git a/Jupiter/DataBuffer.cpp b/Jupiter/DataBuffer.cpp index ee90371..f696be0 100644 --- a/Jupiter/DataBuffer.cpp +++ b/Jupiter/DataBuffer.cpp @@ -74,13 +74,73 @@ Jupiter::DataBuffer::~DataBuffer() void Jupiter::DataBuffer::push(const uint8_t *data, size_t size_) { Jupiter::DataBuffer::secure(size_); - fputs("Pushing: \"", stdout); while (size_-- != 0) - { - fputc(*data, stdout); *Jupiter::DataBuffer::end++ = *data++; +} + +void Jupiter::DataBuffer::peek_from(FILE *file) +{ + fpos_t pos; + fgetpos(file, &pos); + Jupiter::DataBuffer::pop_from(file); + fsetpos(file, &pos); +} + +void Jupiter::DataBuffer::peek_from(FILE *file, size_t size_) +{ + fpos_t pos; + fgetpos(file, &pos); + Jupiter::DataBuffer::pop_from(file, size_); + fsetpos(file, &pos); +} + +void Jupiter::DataBuffer::pop_from(FILE *file) +{ + size_t size_; + fread(&size_, sizeof(size_t), 1, file); + Jupiter::DataBuffer::pop_from(file, size_); +} + +void Jupiter::DataBuffer::pop_from(FILE *file, size_t size_) +{ + Jupiter::DataBuffer::secure(size_); + int chr; + while (size_-- != 0) + { + chr = fgetc(file); + if (chr == EOF) + break; + *Jupiter::DataBuffer::end++ = static_cast(chr); } - puts("\""); +} + +void Jupiter::DataBuffer::copy_to(FILE *file) +{ + fwrite(std::addressof(Jupiter::DataBuffer::size()), sizeof(size_t), 1, file); + Jupiter::DataBuffer::copy_to(file, Jupiter::DataBuffer::size()); +} + +void Jupiter::DataBuffer::copy_to(FILE *file, size_t size_) +{ + fwrite(Jupiter::DataBuffer::head, sizeof(uint8_t), size_, file); +} + +void Jupiter::DataBuffer::copy_to(FILE *file, size_t index, size_t size_) +{ + fwrite(Jupiter::DataBuffer::head + index, sizeof(uint8_t), size_, file); +} + +void Jupiter::DataBuffer::push_to(FILE *file) +{ + Jupiter::DataBuffer::copy_to(file); + Jupiter::DataBuffer::head = Jupiter::DataBuffer::base; + Jupiter::DataBuffer::end = Jupiter::DataBuffer::head; +} + +void Jupiter::DataBuffer::push_to(FILE *file, size_t size_) +{ + Jupiter::DataBuffer::copy_to(file, size_); + Jupiter::DataBuffer::head += size_; } size_t Jupiter::DataBuffer::shrink() diff --git a/Jupiter/DataBuffer.h b/Jupiter/DataBuffer.h index d7ddfab..9fdb087 100644 --- a/Jupiter/DataBuffer.h +++ b/Jupiter/DataBuffer.h @@ -141,6 +141,54 @@ namespace Jupiter */ void push(const uint8_t *data, size_t size); + /** + * @brief Peeks a DataBuffer from a file, and appends it to the buffer. + * + * @param file FILE to peek from + */ + void peek_from(FILE *file); + + /** + * @brief Peeks data from a file, and pushes it to the buffer. + * + * @param file FILE to peek from + * @param size Number of octets to peek + */ + void peek_from(FILE *file, size_t size); + + /** + * @brief Pops a DataBuffer from a file, and appends it to the buffer. + * + * @param file FILE to pop from + */ + void pop_from(FILE *file); + + /** + * @brief Pops data from a file, and pushes it to the buffer. + * + * @param file FILE to pop from + * @param size Number of octets to pop + */ + void pop_from(FILE *file, size_t size); + + /** + * @brief Copies the buffer to a file. + * + * @param file FILE to copy to + */ + void copy_to(FILE *file); + + /** + * @brief Copies data from the buffer to a file. + * + * @param file FILE to copy to + * @param size Number of octets to copy + */ + void copy_to(FILE *file, size_t size); + void copy_to(FILE *file, size_t index, size_t size); + void push_to(FILE *file); + void push_to(FILE *file, size_t size); + /** * @brief Shrinks the buffer to the smallest possible size. * diff --git a/Release/Jupiter.lib b/Release/Jupiter.lib index d152c03..d455bb3 100644 Binary files a/Release/Jupiter.lib and b/Release/Jupiter.lib differ