2
0

FileStream.h 955 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #pragma once
  2. #include <string>
  3. #include <stdexcept>
  4. #include <BellLogger.h>
  5. #include <ByteStream.h>
  6. #include <stdio.h>
  7. /*
  8. * FileStream
  9. *
  10. * A class for reading and writing to files implementing the ByteStream interface.
  11. *
  12. */
  13. namespace bell
  14. {
  15. class FileStream : public ByteStream
  16. {
  17. public:
  18. FileStream(const std::string& path, std::string mode);
  19. ~FileStream();
  20. FILE* file;
  21. /*
  22. * Reads data from the stream.
  23. *
  24. * @param buf The buffer to read data into.
  25. * @param nbytes The size of the buffer.
  26. * @return The number of bytes read.
  27. * @throws std::runtime_error if the stream is closed.
  28. */
  29. size_t read(uint8_t *buf, size_t nbytes);
  30. /*
  31. * Skips nbytes bytes in the stream.
  32. */
  33. size_t skip(size_t nbytes);
  34. size_t position();
  35. size_t size();
  36. // Closes the connection
  37. void close();
  38. };
  39. }