Update README.md
[nemesis.git] / Platform / MemoryStream.cpp
1 /*
2  Copyright (c) 2008 TrueCrypt Developers Association. All rights reserved.
3
4  Governed by the TrueCrypt License 3.0 the full text of which is contained in
5  the file License.txt included in TrueCrypt binary and source code distribution
6  packages.
7 */
8
9 #include "Exception.h"
10 #include "MemoryStream.h"
11
12 namespace TrueCrypt
13 {
14         MemoryStream::MemoryStream (const ConstBufferPtr &data) :
15                 ReadPosition (0)
16         {
17                 Data = vector <byte> (data.Size());
18                 BufferPtr (&Data[0], Data.size()).CopyFrom (data);
19         }
20
21         uint64 MemoryStream::Read (const BufferPtr &buffer)
22         {
23                 if (Data.size() == 0)
24                         throw ParameterIncorrect (SRC_POS);
25
26                 ConstBufferPtr streamBuf (*this);
27                 size_t len = buffer.Size();
28                 if (streamBuf.Size() - ReadPosition < len)
29                         len = streamBuf.Size() - ReadPosition;
30
31                 BufferPtr(buffer).CopyFrom (streamBuf.GetRange (ReadPosition, len));
32                 ReadPosition += len;
33                 return len;
34         }
35
36         void MemoryStream::ReadCompleteBuffer (const BufferPtr &buffer)
37         {
38                 if (Read (buffer) != buffer.Size())
39                         throw InsufficientData (SRC_POS);
40         }
41
42         void MemoryStream::Write (const ConstBufferPtr &data)
43         {
44                 for (uint64 i = 0; i < data.Size(); i++)
45                         Data.push_back (data[i]);
46         }
47 }
This page took 0.014661 seconds and 3 git commands to generate. Download a nemesis OSX (sierra+high sierra, tested/working) binary, with fuse-ext3 via e2fsprogs, at this link. application and installer are signed by screwjack, llc. must install fuse with macFUSE layer first.