1 /* 2 * Copyright 2003-2008, Haiku, Inc. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors : 6 * Michael Wilber 7 * Jérôme Duval 8 */ 9 10 #ifndef STREAM_BUFFER_H 11 #define STREAM_BUFFER_H 12 13 #include <DataIO.h> 14 15 #define MIN_BUFFER_SIZE 512 16 17 class StreamBuffer { 18 public: 19 StreamBuffer(BPositionIO *stream, size_t bufferSize, bool toRead = true); 20 ~StreamBuffer(); 21 22 status_t InitCheck(); 23 // Determines whether the constructor failed or not 24 25 ssize_t Read(void *buffer, size_t size); 26 // copy nbytes from the stream into pinto 27 28 void Write(void *buffer, size_t size); 29 // copy nbytes from the stream into pinto 30 31 bool Seek(off_t position); 32 // seek the stream to the given position 33 34 private: 35 ssize_t _ReadStream(); 36 // Load the stream buffer from the stream 37 38 BPositionIO *fStream; 39 // stream object this object is buffering 40 uint8 *fBuffer; 41 // buffered data from fpStream 42 size_t fBufferSize; 43 // number of bytes of memory allocated for fpBuffer 44 size_t fLen; 45 // number of bytes of actual data in fpBuffer 46 size_t fPos; 47 // current position in the buffer 48 bool fToRead; 49 // whether the stream is to be read. 50 }; 51 52 #endif 53