Tue, 06 Jan 2015 21:39:09 +0100
Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
michael@0 | 1 | // Stream/LSBFEncoder.h |
michael@0 | 2 | |
michael@0 | 3 | #ifndef __STREAM_LSBFENCODER_H |
michael@0 | 4 | #define __STREAM_LSBFENCODER_H |
michael@0 | 5 | |
michael@0 | 6 | #include "../IStream.h" |
michael@0 | 7 | #include "OutBuffer.h" |
michael@0 | 8 | |
michael@0 | 9 | namespace NStream { |
michael@0 | 10 | namespace NLSBF { |
michael@0 | 11 | |
michael@0 | 12 | class CEncoder |
michael@0 | 13 | { |
michael@0 | 14 | COutBuffer m_Stream; |
michael@0 | 15 | int m_BitPos; |
michael@0 | 16 | Byte m_CurByte; |
michael@0 | 17 | public: |
michael@0 | 18 | bool Create(UInt32 bufferSize) { return m_Stream.Create(bufferSize); } |
michael@0 | 19 | void SetStream(ISequentialOutStream *outStream) { m_Stream.SetStream(outStream); } |
michael@0 | 20 | void ReleaseStream() { m_Stream.ReleaseStream(); } |
michael@0 | 21 | void Init() |
michael@0 | 22 | { |
michael@0 | 23 | m_Stream.Init(); |
michael@0 | 24 | m_BitPos = 8; |
michael@0 | 25 | m_CurByte = 0; |
michael@0 | 26 | } |
michael@0 | 27 | HRESULT Flush() |
michael@0 | 28 | { |
michael@0 | 29 | FlushByte(); |
michael@0 | 30 | return m_Stream.Flush(); |
michael@0 | 31 | } |
michael@0 | 32 | |
michael@0 | 33 | void FlushByte() |
michael@0 | 34 | { |
michael@0 | 35 | if(m_BitPos < 8) |
michael@0 | 36 | m_Stream.WriteByte(m_CurByte); |
michael@0 | 37 | m_BitPos = 8; |
michael@0 | 38 | m_CurByte = 0; |
michael@0 | 39 | } |
michael@0 | 40 | |
michael@0 | 41 | void WriteBits(UInt32 value, int numBits); |
michael@0 | 42 | UInt32 GetBitPosition() const { return (8 - m_BitPos); } |
michael@0 | 43 | UInt64 GetProcessedSize() const { |
michael@0 | 44 | return m_Stream.GetProcessedSize() + (8 - m_BitPos + 7) /8; } |
michael@0 | 45 | void WriteByte(Byte b) { m_Stream.WriteByte(b);} |
michael@0 | 46 | }; |
michael@0 | 47 | |
michael@0 | 48 | |
michael@0 | 49 | }} |
michael@0 | 50 | |
michael@0 | 51 | #endif |