File tree Expand file tree Collapse file tree 1 file changed +47
-0
lines changed
Expand file tree Collapse file tree 1 file changed +47
-0
lines changed Original file line number Diff line number Diff line change 1+ class Compactor
2+ {
3+ MemoryStream prev;
4+ MemoryStream stream = new MemoryStream();
5+ public Action<MemoryStream> OnOut;
6+ int remaining = 64000;
7+ public void Push(MemoryStream curr)
8+ {
9+ if (curr.Position >= 64000)
10+ {
11+ Flush();
12+ prev = curr;
13+ Flush();
14+ }
15+ else if(prev == null)
16+ {
17+ prev = curr;
18+ }
19+ else if(curr.Position + prev.Position < remaining)
20+ {
21+ stream.Write(prev.GetBuffer(),0,(int)prev.Position);
22+ remaining -= (int)prev.Position;
23+ prev = curr;
24+ }
25+ else
26+ {
27+ Flush();
28+ prev = curr;
29+ Flush();
30+ }
31+ }
32+
33+ public void Flush()
34+ {
35+ if (stream.Position >0)
36+ {
37+ OnOut(stream);
38+ stream.Position = 0;
39+ remaining = 64000;
40+ }
41+ if(prev != null)
42+ {
43+ OnOut(prev);
44+ prev = null;
45+ }
46+ }
47+ }
You can’t perform that action at this time.
0 commit comments