128 KiB DSC files ought to be enough for everyone
[ntk/apt.git] / ftparchive / sources.cc
CommitLineData
ce928105 1#include <string>
31be38d2 2#include <sstream>
ce928105
MV
3
4// for memcpy
5#include <cstring>
6
7#include <apt-pkg/error.h>
8#include <apt-pkg/gpgv.h>
9
10#include "sources.h"
11
31be38d2 12bool DscExtract::TakeDsc(const void *newData, unsigned long long newSize)
ce928105 13{
ce928105
MV
14 if (newSize == 0)
15 {
31be38d2
DK
16 // adding two newlines 'off record' for pkgTagSection.Scan() calls
17 Data = "\n\n";
ce928105
MV
18 Length = 0;
19 return true;
20 }
31be38d2
DK
21
22 Data = std::string((const char*)newData, newSize);
23 // adding two newlines 'off record' for pkgTagSection.Scan() calls
24 Data.append("\n\n");
ce928105
MV
25 Length = newSize;
26
27 return true;
28}
29
30bool DscExtract::Read(std::string FileName)
31{
31be38d2
DK
32 Data.clear();
33 Length = 0;
34
ce928105
MV
35 FileFd F;
36 if (OpenMaybeClearSignedFile(FileName, F) == false)
37 return false;
ce928105
MV
38
39 IsClearSigned = (FileName != F.Name());
40
31be38d2
DK
41 std::ostringstream data;
42 char buffer[1024];
43 do {
44 unsigned long long actual = 0;
45 if (F.Read(buffer, sizeof(buffer)-1, &actual) == false)
46 return _error->Errno("read", "Failed to read dsc file %s", FileName.c_str());
47 if (actual == 0)
48 break;
49 Length += actual;
50 buffer[actual] = '\0';
51 data << buffer;
52 } while(true);
53
54 // adding two newlines 'off record' for pkgTagSection.Scan() calls
55 data << "\n\n";
56 Data = data.str();
ce928105
MV
57 return true;
58}
59
60