-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
123 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#pragma once | ||
#include <fstream> | ||
#include <iostream> | ||
|
||
inline unsigned char* ReadPartialUnsignedFile(std::string file, size_t& bytes) //reads 'bytes' bytes from file - Bytes will be updated to match the bytes read | ||
{ | ||
unsigned char* buffer = new unsigned char[bytes]; | ||
std::ifstream in = std::ifstream(file,std::ios::binary | std::ios::ate); | ||
size_t size = in.tellg(); | ||
in.seekg(0,std::ios::beg); | ||
if(bytes > size) | ||
{ | ||
//Err | ||
std::cout << "Trying to read more bytes than is available in file: '" << file << "', trying to read: '" << bytes << "' but file did only contain: '" << size << "' bytes - reading maxsize instead" << std::endl; | ||
bytes = size; | ||
} | ||
if(in.read(reinterpret_cast<char*>(buffer),size)) | ||
{ | ||
in.close(); | ||
return buffer; | ||
} | ||
else | ||
{ | ||
in.close(); | ||
std::cout << "File read error" << std::endl; | ||
delete[] buffer; | ||
bytes = 1; | ||
return new unsigned char[1]; | ||
} | ||
|
||
} | ||
inline unsigned char* ReadUnsignedFile(std::string file, size_t& bytesRead) //Reads the whole file | ||
{ | ||
unsigned char* buffer; | ||
std::ifstream in = std::ifstream(file,std::ios::binary | std::ios::ate); | ||
size_t size = in.tellg(); | ||
in.seekg(0,std::ios::beg); | ||
bytesRead = size; | ||
buffer = new unsigned char[size]; | ||
if(in.read(reinterpret_cast<char*>(buffer),size)) | ||
{ | ||
in.close(); | ||
return buffer; | ||
} | ||
else | ||
{ | ||
in.close(); | ||
std::cout << "File read error" << std::endl; | ||
delete[] buffer; | ||
bytesRead = 1; | ||
return new unsigned char[1]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.