diff --git a/lib/libfnd/include/fnd/io.h b/lib/libfnd/include/fnd/io.h index 58aa895..291a79b 100644 --- a/lib/libfnd/include/fnd/io.h +++ b/lib/libfnd/include/fnd/io.h @@ -1,6 +1,5 @@ #pragma once #include -#include namespace fnd { @@ -13,10 +12,6 @@ namespace fnd #endif size_t getFileSize(const std::string& path); - void readFile(const std::string& path, MemoryBlob& blob); - void readFile(const std::string& path, size_t offset, size_t len, MemoryBlob& blob); - void writeFile(const std::string& path, const MemoryBlob& blob); - void writeFile(const std::string& path, const byte_t* data, size_t len); void makeDirectory(const std::string& path); void getEnvironVar(std::string& var, const std::string& key); void appendToPath(std::string& base, const std::string& add); diff --git a/lib/libfnd/source/io.cpp b/lib/libfnd/source/io.cpp index 9bb966b..1c1d5dd 100644 --- a/lib/libfnd/source/io.cpp +++ b/lib/libfnd/source/io.cpp @@ -11,9 +11,6 @@ using namespace fnd; -static const std::string kModuleName = "IO"; -static const size_t kBlockSize = 0x100000; - size_t io::getFileSize(const std::string& path) { std::ifstream f; @@ -25,112 +22,6 @@ size_t io::getFileSize(const std::string& path) return static_cast(f.tellg() - begin_pos); } -void io::readFile(const std::string& path, MemoryBlob & blob) -{ - fnd::SimpleFile file; - try - { - file.open(path, file.Read); - } - catch (const fnd::Exception&) - { - throw fnd::Exception(kModuleName, "Failed to open \"" + path + "\": does not exist"); - } - - size_t filesz, filepos; - filesz = file.size(); - - - try { - blob.alloc(filesz); - } - catch (const fnd::Exception& e) - { - throw fnd::Exception(kModuleName, "Failed to allocate memory for file: " + std::string(e.what())); - } - - for (filepos = 0; filesz > kBlockSize; filesz -= kBlockSize, filepos += kBlockSize) - { - file.read(blob.getBytes() + filepos, kBlockSize); - } - - if (filesz) - { - file.read(blob.getBytes() + filepos, filesz); - } -} - -void fnd::io::readFile(const std::string& path, size_t offset, size_t len, MemoryBlob& blob) -{ - fnd::SimpleFile file; - try - { - file.open(path, file.Read); - } catch (const fnd::Exception&) - { - throw fnd::Exception(kModuleName, "Failed to open \"" + path + "\": does not exist"); - } - - size_t filesz, filepos; - filesz = file.size(); - file.seek(offset); - - if (filesz < len || filesz < offset || filesz < (offset + len)) - { - throw Exception(kModuleName, "Failed to open \"" + path + "\": file to small"); - } - - try - { - blob.alloc(filesz); - } catch (const fnd::Exception& e) - { - throw fnd::Exception(kModuleName, "Failed to allocate memory for file: " + std::string(e.what())); - } - - for (filepos = 0; filesz > kBlockSize; filesz -= kBlockSize, filepos += kBlockSize) - { - file.read(blob.getBytes() + filepos, kBlockSize); - } - - if (filesz) - { - file.read(blob.getBytes() + filepos, filesz); - } -} - -void io::writeFile(const std::string& path, const MemoryBlob & blob) -{ - writeFile(path, blob.getBytes(), blob.getSize()); -} - -void io::writeFile(const std::string & path, const byte_t * data, size_t len) -{ - fnd::SimpleFile file; - try - { - file.open(path, file.Create); - } catch (const fnd::Exception&) - { - throw fnd::Exception(kModuleName, "Failed to open \"" + path + "\": does not exist"); - } - - size_t filesz, filepos; - - filesz = len; - - - for (filepos = 0; filesz > kBlockSize; filesz -= kBlockSize, filepos += kBlockSize) - { - file.write(data + filepos, kBlockSize); - } - - if (filesz) - { - file.write(data + filepos, filesz); - } -} - void io::makeDirectory(const std::string& path) { #ifdef _WIN32