7#include "exiv2lib_export.h"
18#ifndef EXV_XPATH_MEMIO
19#define EXV_XPATH_MEMIO 0
82 virtual size_t write(
const byte* data,
size_t wcount) = 0;
100 virtual int putb(
byte data) = 0;
124 virtual size_t read(
byte* buf,
size_t rcount) = 0;
186 virtual byte*
mmap(
bool isWriteable =
false) = 0;
203 [[nodiscard]]
virtual size_t tell()
const = 0;
209 [[nodiscard]]
virtual size_t size()
const = 0;
211 [[nodiscard]]
virtual bool isopen()
const = 0;
213 [[nodiscard]]
virtual int error()
const = 0;
215 [[nodiscard]]
virtual bool eof()
const = 0;
221 [[nodiscard]]
virtual const std::string&
path() const noexcept = 0;
279#ifdef EXV_ENABLE_FILESYSTEM
315 int open(
const std::string& mode);
340 size_t write(
const byte* data,
size_t wcount)
override;
382 size_t read(
byte* buf,
size_t rcount)
override;
423 byte*
mmap(
bool isWriteable =
false)
override;
444 [[nodiscard]]
size_t tell()
const override;
451 [[nodiscard]]
size_t size()
const override;
453 [[nodiscard]]
bool isopen()
const override;
455 [[nodiscard]]
int error()
const override;
457 [[nodiscard]]
bool eof()
const override;
459 [[nodiscard]]
const std::string&
path() const noexcept override;
480 std::unique_ptr<Impl> p_;
528 int close()
override;
539 size_t write(
const byte* data,
size_t wcount)
override;
558 int putb(
byte data)
override;
582 size_t read(
byte* buf,
size_t rcount)
override;
617 byte*
mmap(
bool =
false)
override;
627 [[nodiscard]]
size_t tell()
const override;
633 [[nodiscard]]
size_t size()
const override;
635 [[nodiscard]]
bool isopen()
const override;
637 [[nodiscard]]
int error()
const override;
639 [[nodiscard]]
bool eof()
const override;
641 [[nodiscard]]
const std::string&
path()
const noexcept override;
663 std::unique_ptr<Impl> p_;
676 XPathIo(
const std::string& path);
689 void ReadDataUri(
const std::string& path);
691#elif defined(EXV_ENABLE_FILESYSTEM)
741 std::string tempFilePath_;
778 int close()
override;
783 size_t write(
const byte* data,
size_t wcount)
override;
804 int putb(
byte data)
override;
832 size_t read(
byte* buf,
size_t rcount)
override;
864 byte*
mmap(
bool =
false)
override;
877 [[nodiscard]]
size_t tell()
const override;
883 [[nodiscard]]
size_t size()
const override;
885 [[nodiscard]]
bool isopen()
const override;
887 [[nodiscard]]
int error()
const override;
889 [[nodiscard]]
bool eof()
const override;
891 [[nodiscard]]
const std::string&
path() const noexcept override;
927 explicit HttpIo(
const std::string& url,
size_t blockSize = 1024);
952 explicit CurlIo(
const std::string& url,
size_t blockSize = 0);
959 size_t write(
const byte* data,
size_t wcount)
override;
992EXIV2API
size_t curlWriter(
char* data,
size_t size,
size_t nmemb, std::string* writerData);
An interface for simple binary IO.
Definition basicio.hpp:35
virtual size_t write(const byte *data, size_t wcount)=0
Write data to the IO source. Current IO position is advanced by the number of bytes written.
virtual bool isopen() const =0
Returns true if the IO source is open, otherwise false.
virtual int open()=0
Open the IO source using the default access mode. The default mode should allow for reading and writi...
Position
Seek starting positions.
Definition basicio.hpp:41
virtual bool eof() const =0
Returns true if the IO position has reached the end, otherwise false.
virtual void populateFakeData()=0
Mark all the bNone blocks to bKnow. This avoids allocating memory for parts of the file that contain ...
virtual size_t size() const =0
Get the current size of the IO source in bytes.
virtual int getb()=0
Read one byte from the IO source. Current IO position is advanced by one byte.
byte * bigBlock_
this is allocated and populated by mmap()
Definition basicio.hpp:235
virtual int close()=0
Close the IO source. After closing a BasicIo instance can not be read or written. Closing flushes any...
virtual size_t tell() const =0
Get the current IO position.
virtual ~BasicIo()=default
Destructor.
void readOrThrow(byte *buf, size_t rcount, ErrorCode err=ErrorCode::kerCorruptedMetadata)
Safe version of read() that checks for errors and throws an exception if the read was unsuccessful.
Definition basicio.cpp:56
virtual int seek(int64_t offset, Position pos)=0
Move the current IO position.
virtual const std::string & path() const noexcept=0
Return the path to the IO resource. Often used to form comprehensive error messages where only a Basi...
virtual int munmap()=0
Remove a mapping established with mmap(). If the mapped area is writeable, this ensures that changes ...
virtual size_t write(BasicIo &src)=0
Write data that is read from another BasicIo instance to the IO source. Current IO position is advanc...
std::unique_ptr< BasicIo > UniquePtr
BasicIo auto_ptr type.
Definition basicio.hpp:38
virtual DataBuf read(size_t rcount)=0
Read data from the IO source. Reading starts at the current IO position and the position is advanced ...
virtual void transfer(BasicIo &src)=0
Remove all data from this object's IO source and then transfer data from the src BasicIo object into ...
virtual int putb(byte data)=0
Write one byte to the IO source. Current IO position is advanced by one byte.
virtual int error() const =0
Returns 0 if the IO source is in a valid state, otherwise nonzero.
virtual byte * mmap(bool isWriteable=false)=0
Direct access to the IO data. For files, this is done by mapping the file into the process's address ...
virtual size_t read(byte *buf, size_t rcount)=0
Read data from the IO source. Reading starts at the current IO position and the position is advanced ...
void seekOrThrow(int64_t offset, Position pos, ErrorCode err)
Safe version of seek() that checks for errors and throws an exception if the seek was unsuccessful.
Definition basicio.cpp:62
size_t write(BasicIo &src) override
Write access is only available for some protocols. This method will call RemoteIo::write(BasicIo& src...
size_t write(const byte *data, size_t wcount) override
Write access is only available for some protocols. This method will call RemoteIo::write(const byte* ...
CurlIo(const std::string &url, size_t blockSize=0)
Constructor that accepts the URL on which IO will be performed.
int open(const std::string &mode)
Open the file using the specified mode.
DataBuf read(size_t rcount) override
Read data from the file. Reading starts at the current file position and the position is advanced by ...
~FileIo() override
Destructor. Flushes and closes an open file.
bool isopen() const override
Returns true if the file is open, otherwise false.
int open() override
Open the file using the default access mode of "rb". This method can also be used to "reopen" a file ...
int seek(int64_t offset, Position pos) override
Move the current IO position.
size_t write(const byte *data, size_t wcount) override
Write data to the file. The file position is advanced by the number of bytes written.
virtual void setPath(const std::string &path)
close the file source and set a new path.
size_t tell() const override
Get the current file position.
void populateFakeData() override
Mark all the bNone blocks to bKnow. This avoids allocating memory for parts of the file that contain ...
const std::string & path() const noexcept override
Returns the path of the file.
size_t read(byte *buf, size_t rcount) override
Read data from the file. Reading starts at the current file position and the position is advanced by ...
int munmap() override
Remove a mapping established with mmap(). If the mapped area is writeable, this ensures that changes ...
int error() const override
Returns 0 if the file is in a valid state, otherwise nonzero.
bool eof() const override
Returns true if the file position has reached the end, otherwise false.
int close() override
Flush and unwritten data and close the file . It is safe to call close on an already closed instance.
size_t write(BasicIo &src) override
Write data that is read from another BasicIo instance to the file. The file position is advanced by t...
FileIo(const std::string &path)
Constructor that accepts the file path on which IO will be performed. The constructor does not open t...
size_t size() const override
Flush any buffered writes and get the current file size in bytes.
int getb() override
Read one byte from the file. The file position is advanced by one byte.
byte * mmap(bool isWriteable=false) override
Map the file into the process's address space. The file must be open before mmap() is called....
int putb(byte data) override
Write one byte to the file. The file position is advanced by one byte.
void transfer(BasicIo &src) override
Remove the contents of the file and then transfer data from the src BasicIo object into the empty fil...
HttpIo(const std::string &url, size_t blockSize=1024)
Constructor that accepts the http URL on which IO will be performed. The constructor does not open th...
IoCloser & operator=(const IoCloser &)=delete
Assignment operator.
IoCloser(BasicIo &bio)
Constructor, takes a BasicIo reference.
Definition basicio.hpp:251
virtual ~IoCloser()
Destructor, closes the BasicIo reference.
Definition basicio.hpp:254
void close()
Close the BasicIo if it is open.
Definition basicio.hpp:262
BasicIo & bio_
The BasicIo reference.
Definition basicio.hpp:270
IoCloser(const IoCloser &)=delete
Copy constructor.
Internal Pimpl structure of class MemIo.
Definition basicio.cpp:563
Provides binary IO on blocks of memory by implementing the BasicIo interface. A copy-on-write impleme...
Definition basicio.hpp:497
DataBuf read(size_t rcount) override
Read data from the memory block. Reading starts at the current IO position and the position is advanc...
Definition basicio.cpp:819
void transfer(BasicIo &src) override
Clear the memory block and then transfer data from the src BasicIo object into a new block of memory.
Definition basicio.cpp:710
size_t tell() const override
Get the current IO position.
Definition basicio.cpp:797
size_t write(const byte *data, size_t wcount) override
Write data to the memory block. If needed, the size of the internal memory block is expanded....
Definition basicio.cpp:701
int seek(int64_t offset, Position pos) override
Move the current IO position.
Definition basicio.cpp:761
bool isopen() const override
Always returns true.
Definition basicio.cpp:811
MemIo & operator=(const MemIo &)=delete
Assignment operator.
const std::string & path() const noexcept override
Returns a dummy path, indicating that memory access is used.
Definition basicio.cpp:855
int open() override
Memory IO is always open for reading and writing. This method therefore only resets the IO position t...
Definition basicio.cpp:805
bool eof() const override
Returns true if the IO position has reached the end, otherwise false.
Definition basicio.cpp:851
MemIo()
Default constructor that results in an empty object.
Definition basicio.cpp:689
int getb() override
Read one byte from the memory block. The IO position is advanced by one byte.
Definition basicio.cpp:839
byte * mmap(bool=false) override
Allow direct access to the underlying data buffer. The buffer is not protected against write access i...
Definition basicio.cpp:789
void populateFakeData() override
Mark all the bNone blocks to bKnow. This avoids allocating memory for parts of the file that contain ...
Definition basicio.cpp:860
MemIo(const MemIo &)=delete
Copy constructor.
int putb(byte data) override
Write one byte to the memory block. The IO position is advanced by one byte.
Definition basicio.cpp:755
size_t size() const override
Get the current memory buffer size in bytes.
Definition basicio.cpp:801
int munmap() override
Remove a mapping established with mmap(). If the mapped area is writeable, this ensures that changes ...
Definition basicio.cpp:793
int error() const override
Always returns 0.
Definition basicio.cpp:847
int close() override
Does nothing on MemIo objects.
Definition basicio.cpp:815
Internal Pimpl abstract structure of class RemoteIo.
Definition basicio.cpp:1001
RemoteIo()
Destructor. Releases all managed memory.
int close() override
Reset the IO position to the start. It does not release the data.
Definition basicio.cpp:1143
int error() const override
Always returns 0.
Definition basicio.cpp:1366
std::unique_ptr< Impl > p_
Pointer to implementation.
Definition basicio.hpp:908
size_t write(const byte *data, size_t wcount) override
Not support this method.
Definition basicio.cpp:1158
size_t size() const override
Get the current memory buffer size in bytes.
Definition basicio.cpp:1358
int open() override
Connect to the remote server, get the size of the remote file and allocate the array of blocksMap.
Definition basicio.cpp:1108
void populateFakeData() override
Mark all the bNone blocks to bKnow. This avoids allocating memory for parts of the file that contain ...
Definition basicio.cpp:1378
byte * mmap(bool=false) override
Not support.
Definition basicio.cpp:1328
const std::string & path() const noexcept override
Returns the URL of the file.
Definition basicio.cpp:1374
size_t tell() const override
Get the current IO position.
Definition basicio.cpp:1354
int seek(int64_t offset, Position pos) override
Move the current IO position.
Definition basicio.cpp:1304
bool eof() const override
Returns true if the IO position has reached the end, otherwise false.
Definition basicio.cpp:1370
int munmap() override
Not support.
Definition basicio.cpp:1350
int putb(byte data) override
Not support.
Definition basicio.cpp:1230
bool isopen() const override
Returns true if the memory area is allocated.
Definition basicio.cpp:1362
void transfer(BasicIo &src) override
Remove the contents of the file and then transfer data from the src BasicIo object into the empty fil...
Definition basicio.cpp:1296
DataBuf read(size_t rcount) override
Read data from the memory blocks. Reading starts at the current IO position and the position is advan...
Definition basicio.cpp:1234
int getb() override
Read one byte from the memory blocks. The IO position is advanced by one byte. If the memory block is...
Definition basicio.cpp:1282
Provides binary IO for the data from stdin and data uri path.
Definition basicio.hpp:692
void transfer(BasicIo &src) override
Change the name of the temp file and make it untemporary before calling the method of superclass File...
static constexpr auto TEMP_FILE_EXT
The extension of the temporary file which is created when getting input data to read metadata....
Definition basicio.hpp:698
static constexpr auto GEN_FILE_EXT
The extension of the generated file which is created when getting input data to add or modify the met...
Definition basicio.hpp:703
XPathIo(const std::string &orgPath)
Default constructor that reads data from stdin/data uri path and writes them to the temp file.
static std::string writeDataToFile(const std::string &orgPath)
Read the data from stdin/data uri path and write them to the file.
~XPathIo() override
Destructor. Releases all managed memory and removes the temp file.
Error class for exceptions, log message class.
Class CrwImage to access Canon CRW images. References: The Canon RAW (CRW) File Format by Phil Harv...
Definition asfvideo.hpp:15
EXIV2API size_t curlWriter(char *data, size_t size, size_t nmemb, std::string *writerData)
The callback function is called by libcurl to write the data.
ErrorCode
Complete list of all Exiv2 error codes.
Definition error.hpp:162
EXIV2API size_t writeFile(const DataBuf &buf, const std::string &path)
Write DataBuf buf to file path.
EXIV2API DataBuf readFile(const std::string &path)
Read file path into a DataBuf, which is returned.
Utility class containing a character array. All it does is to take care of memory allocation and dele...
Definition types.hpp:124