forked from floft/sprouts
-
Notifications
You must be signed in to change notification settings - Fork 3
/
compressed_stream.cpp
69 lines (61 loc) · 1.45 KB
/
compressed_stream.cpp
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include "compressed_stream.h"
#include "util.h"
#include <iostream>
#include <cstdlib>
#include <thread>
/**************
*Description:
*Input:
*Output:
**************/
#if 0 // use demo code
namespace
{
class DumpWriter final : public Writer
{
public:
virtual void writeByte(uint8_t v) override
{
cout << hex << (unsigned)(v >> 4) << (unsigned)(v & 0xF) << endl << dec;
}
};
void dumpRead(shared_ptr<Reader> preader)
{
ExpandReader reader(preader);
try
{
while(true)
{
cout << (char)reader.readByte();
}
}
catch(EOFException &e)
{
}
cout << endl;
}
initializer init1([]()
{
cout << "test compression :\n";
thread readerThread;
{
StreamPipe pipe;
readerThread = thread(dumpRead, pipe.preader());
CompressWriter w(pipe.pwriter());
for(int i = 0; i < 65536; i++)
{
for(const char *str =
"abcdefghij012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123abcdefg\n";
*str; str++)
{
w.writeByte(*str);
}
w.flush();
}
w.flush();
}
readerThread.join();
exit(0);
});
}
#endif // use demo code