other-licenses/7zstub/src/7zip/Common/LSBFEncoder.h

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

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.

     1 // Stream/LSBFEncoder.h
     3 #ifndef __STREAM_LSBFENCODER_H
     4 #define __STREAM_LSBFENCODER_H
     6 #include "../IStream.h"
     7 #include "OutBuffer.h"
     9 namespace NStream {
    10 namespace NLSBF {
    12 class CEncoder
    13 {
    14   COutBuffer m_Stream;
    15   int m_BitPos;
    16   Byte m_CurByte;
    17 public:
    18   bool Create(UInt32 bufferSize) { return m_Stream.Create(bufferSize); }
    19   void SetStream(ISequentialOutStream *outStream) { m_Stream.SetStream(outStream); }
    20   void ReleaseStream() { m_Stream.ReleaseStream(); }
    21   void Init()
    22   {
    23     m_Stream.Init();
    24     m_BitPos = 8; 
    25     m_CurByte = 0;
    26   }
    27   HRESULT Flush()
    28   {
    29     FlushByte();
    30     return m_Stream.Flush();
    31   }
    33   void FlushByte()
    34   {
    35     if(m_BitPos < 8)
    36       m_Stream.WriteByte(m_CurByte);
    37     m_BitPos = 8; 
    38     m_CurByte = 0;
    39   }
    41   void WriteBits(UInt32 value, int numBits);
    42   UInt32 GetBitPosition() const {  return (8 - m_BitPos); }
    43   UInt64 GetProcessedSize() const { 
    44       return m_Stream.GetProcessedSize() + (8 - m_BitPos + 7) /8; }
    45   void WriteByte(Byte b) { m_Stream.WriteByte(b);}
    46 };
    49 }}
    51 #endif

mercurial