Go to the documentation of this file.
39 #include <boost/format.hpp>
40 #include <boost/make_shared.hpp>
45 # define fseeko fseeko64
46 # define ftello ftello64
50 # define fseeko _fseeki64
51 # define ftello _ftelli64
52 # define fileno _fileno
53 # define ftruncate _chsize
90 #if defined(_MSC_VER) && (_MSC_VER >= 1400 )
91 fopen_s( &
file_, filename.c_str(),
"r" );
93 file_ = fopen(filename.c_str(),
"r");
97 #if defined(_MSC_VER) && (_MSC_VER >= 1400 )
98 fopen_s( &
file_, filename.c_str(),
"w+b" );
100 file_ = fopen(filename.c_str(),
"w+b");
103 if (fclose(
file_) != 0)
104 throw BagIOException((format(
"Error closing file: %1%") % filename.c_str()).str());
107 #if defined(_MSC_VER) && (_MSC_VER >= 1400 )
108 fopen_s( &
file_, filename.c_str(),
"r+b" );
110 file_ = fopen(filename.c_str(),
"r+b");
115 #if defined(_MSC_VER) && (_MSC_VER >= 1400 )
116 fopen_s( &
file_, filename.c_str(), mode.c_str() );
118 file_ = fopen(filename.c_str(), mode.c_str());
122 throw BagIOException((format(
"Error opening file: %1%") % filename.c_str()).str());
124 read_stream_ = boost::make_shared<UncompressedStream>(
this);
125 write_stream_ = boost::make_shared<UncompressedStream>(
this);
131 return feof(
file_) == 0 && ferror(
file_) == 0;
145 int success = fclose(
file_);
161 throw BagIOException(
"Can't set compression mode before opening a file");
166 stream->startWrite();
173 throw BagIOException(
"Can't set compression mode before opening a file");
189 int success = fseeko(
file_, offset, origin);
204 int fd = fileno(
file_);
205 return ftruncate(fd, length) == 0;
211 if(fgets(buffer, 1024,
file_))
222 stream_factory_->getStream(compression)->decompress(dest, dest_len, source, source_len);
std::string getFileName() const
return path of currently open file
void setWriteMode(CompressionType type)
ChunkedFile reads and writes files which contain interleaved chunks of compressed and uncompressed da...
static void setFile(Stream &a, ChunkedFile *file)
char * unused_
extra data read by compressed stream
void seek(uint64_t offset, int origin=std::ios_base::beg)
seek to given offset from origin
int nUnused_
number of bytes of extra data read by compressed stream
void open(std::string const &filename, std::string const &mode)
void openReadWrite(std::string const &filename)
open file for reading & writing
uint64_t compressed_in_
number of bytes written to current compressed stream
void swap(Bag &a, Bag &b)
uint64_t getOffset() const
return current offset from the beginning of the file
bool isOpen() const
return true if file is open for reading or writing
Exception thrown when on IO problems.
bool good() const
return true if hasn't reached end-of-file and no error
uint32_t getCompressedBytesIn() const
return the number of bytes written to current compressed stream
void close()
close the file
boost::shared_ptr< Stream > write_stream_
void openWrite(std::string const &filename)
open file for writing
void decompress(CompressionType compression, uint8_t *dest, unsigned int dest_len, uint8_t *source, unsigned int source_len)
boost::shared_ptr< StreamFactory > stream_factory_
void setReadMode(CompressionType type)
boost::shared_ptr< Stream > read_stream_
uint64_t offset_
current position in the file
void swap(ChunkedFile &other)
void openRead(std::string const &filename)
open file for reading
void read(void *ptr, size_t size)
read size bytes from the file into ptr
void write(std::string const &s)
std::string filename_
path to file
bool truncate(uint64_t length)
rosbag_storage
Author(s): Dirk Thomas
, Jacob Perron
autogenerated on Sat Sep 14 2024 02:59:52