-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathStream.h
51 lines (40 loc) · 1.21 KB
/
Stream.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*
* Stream.h
* swfparser
*
* Created by Rintarou on 2010/5/20.
* Copyright 2010 http://rintarou.dyndns.org. All rights reserved.
*
*/
//#include "common.h"
#include "stdio.h"
#ifndef _STREAM_H_
#define _STREAM_H_
// As a simple interface for stream read so far.
// Todo : Need to extend for more general usage.
class Stream {
public:
// return number of bytes read or -1 if error, exactly like fread()
virtual int read(unsigned char *dst, unsigned int numBytes) = 0;
};
class FileStream : Stream {
public:
FileStream(FILE *fstream);
int read(unsigned char *dst, unsigned int numBytes);
private:
FILE *_fstream;
};
class MemoryStream : Stream {
public:
MemoryStream(unsigned char *streamStart, unsigned int streamLength, int isOwner); // attach
~MemoryStream();
int read(unsigned char *dst, unsigned int numBytes);
unsigned int length() { return _stream_length; };
void * getStartPtr() { return (void *)_stream_start; };
private:
unsigned int _stream_length;
unsigned char *_stream_start;
unsigned int _stream_pos; // current pos
int _isOwner; // if isOwner, need to free the memory in destructor.
};
#endif // _STREAM_H_