other-licenses/7zstub/src/7zip/Common/InOutTempBuffer.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 // Util/InOutTempBuffer.h
     3 #ifndef __IN_OUT_TEMP_BUFFER_H
     4 #define __IN_OUT_TEMP_BUFFER_H
     6 #include "../../Windows/FileIO.h"
     7 #include "../../Windows/FileDir.h"
     8 #include "../../Common/MyCom.h"
    10 #include "../IStream.h"
    12 class CInOutTempBuffer
    13 {
    14   NWindows::NFile::NDirectory::CTempFile _tempFile;
    15   NWindows::NFile::NIO::COutFile _outFile;
    16   NWindows::NFile::NIO::CInFile _inFile;
    17   Byte *_buffer;
    18   UInt32 _bufferPosition;
    19   UInt32 _currentPositionInBuffer;
    20   CSysString _tmpFileName;
    21   bool _tmpFileCreated;
    23   UInt64 _fileSize;
    25   bool WriteToFile(const void *data, UInt32 size);
    26 public:
    27   CInOutTempBuffer();
    28   ~CInOutTempBuffer();
    29   void Create();
    31   void InitWriting();
    32   bool Write(const void *data, UInt32 size);
    33   UInt64 GetDataSize() const { return _fileSize; }
    34   bool FlushWrite();
    35   bool InitReading();
    36   HRESULT WriteToStream(ISequentialOutStream *stream);
    37 };
    39 class CSequentialOutTempBufferImp: 
    40   public ISequentialOutStream,
    41   public CMyUnknownImp
    42 {
    43   CInOutTempBuffer *_buffer;
    44 public:
    45   // CSequentialOutStreamImp(): _size(0) {}
    46   // UInt32 _size;
    47   void Init(CInOutTempBuffer *buffer)  { _buffer = buffer; }
    48   // UInt32 GetSize() const { return _size; }
    50   MY_UNKNOWN_IMP
    52   STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);
    53 };
    55 #endif

mercurial