26#include <wx/wfstream.h>
27#include <wx/txtstrm.h>
34 0xA1, 0xB1, 0x1A, 0xE1 };
37 bool aIgnoreWhitespace )
39 wxFFileInputStream input( aFilePath );
41 if( input.IsOk() && !input.Eof() )
44 wxTextInputStream
text( input );
45 wxString line =
text.ReadLine();
47 if( aIgnoreWhitespace )
49 while( !input.Eof() && line.IsEmpty() )
50 line =
text.ReadLine().Trim(
false );
53 if( line.StartsWith( aPrefix ) )
64 wxFFileInputStream input( aFilePath );
66 if( input.IsOk() && !input.Eof() )
68 if(
static_cast<size_t>( input.GetLength() ) < aOffset + aHeader.size() )
74 if( !input.SeekI( aOffset, wxFromStart ) )
78 std::vector<uint8_t> parsedHeader( aHeader.size() );
80 if( !input.ReadAll( parsedHeader.data(), parsedHeader.size() ) )
83 return parsedHeader == aHeader;
92 constexpr size_t c_BufSize = 1024;
93 wxFFileInputStream input( aFilePath );
98 uint8_t buf[ c_BufSize ];
99 while ( !input.Eof() )
101 input.Read( buf, c_BufSize);
102 size_t byteCount = input.LastRead();
105 hash.
addData( buf, byteCount );
116 return std::optional<wxString>();
A streaming C++ equivalent for MurmurHash3_x64_128.
FORCE_INLINE void addData(const uint8_t *data, size_t length)
FORCE_INLINE HASH_128 digest()
std::optional< wxString > fileHashMMH3(const wxString &aFilePath)
Calculates an MMH3 hash of a given file.
bool fileStartsWithPrefix(const wxString &aFilePath, const wxString &aPrefix, bool aIgnoreWhitespace)
Check if a file starts with a defined string.
const std::vector< uint8_t > COMPOUND_FILE_HEADER
bool fileHasBinaryHeader(const wxString &aFilePath, const std::vector< uint8_t > &aHeader, size_t aOffset)
Check if a file starts with a defined binary header.
std::string ToString() const