AsyncBinaryFile

Files CCore/inc/AsyncBinaryFile.h CCore/src/AsyncBinaryFile.cpp

An AsyncBinaryFile object can be used as a serialization output device. It puts data bytes into the output file. This class is similar to the PrintAsyncFile class, but provides binary output capabilities rather than textual. It contains inside the AsyncFile object.


class AsyncBinaryFile : NoCopy , public PutDevBase<AsyncBinaryFile>
 {
   AsyncFile file;

   ....

  public: 
   
   // constructors
  
   AsyncBinaryFile();
   
   explicit AsyncBinaryFile(StrLen file_name,FileOpenFlags oflags=Open_ToWrite);
   
   AsyncBinaryFile(StrLen dev_name,StrLen dev_file_name,FileOpenFlags oflags=Open_ToWrite);

   ~AsyncBinaryFile();
   
   // methods
   
   bool isOpened() const;
   
   void open(StrLen file_name,FileOpenFlags oflags=Open_ToWrite);
   
   void open(StrLen dev_name,StrLen dev_file_name,FileOpenFlags oflags=Open_ToWrite);

   void soft_close(FileMultiError &errout);
   
   void close();
   
   void preserveFile() { file.preserveFile(); }
   
   void setLargeWriteLen(ulen large_write_len) { file.setLargeWriteLen(large_write_len); }
   
   void wait() { file.wait(); }
   
   void wait_final() { file.wait_final(); }
   
   void wait(MSec timeout) { file.wait(timeout); }
   
   void cancel_and_wait() { file.cancel_and_wait(); }
   
   // put
   
   void do_put(uint8 value);
   
   void do_put(const uint8 *ptr,ulen len);
   
   PtrLen<uint8> do_putRange(ulen len);
   
   void flush();
 };

A file must be opened before any serialization operation. You can do it using the constructor or the method open(). file_name and oflags specifies the file to be opened and the open flags. The file may be also specified using the device name and the device file name.

Destructor completes operations, closes the file and reports errors if any.

isOpened() returns true, if the file is opened.

open() opens the given file.

soft_close() flushes output and closes the file. Errors are reported to the given FileMultiError object.

close() flushes output and closes the file. An exception is thrown in case of errors.

preserveFile() preserves the file, opened with the Open_AutoDelete open flag.

Other methods are direct calls of the correspondent AsyncFile methods. Usually they are not required.

do_putRange() operation is not implemented and throw an exception.

flush() flushes data from the buffer to the file.