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 off_t Seek(off_t position, uint32 seekMode); 32 // seek the stream to the given position 33 34 off_t Position(); 35 // return the actual position 36 private: 37 ssize_t _ReadStream(); 38 // Load the stream buffer from the stream 39 40 BPositionIO *fStream; 41 // stream object this object is buffering 42 uint8 *fBuffer; 43 // buffered data from fpStream 44 size_t fBufferSize; 45 // number of bytes of memory allocated for fpBuffer 46 size_t fLen; 47 // number of bytes of actual data in fpBuffer 48 size_t fPos; 49 // current position in the buffer 50 bool fToRead; 51 // whether the stream is to be read. 52 }; 53 54 #endif 55