Cuberite
A lightweight, fast and extensible game server for Minecraft
GZipFile.cpp
Go to the documentation of this file.
1 
2 // GZipFile.cpp
3 
4 // Implements the cGZipFile class representing a RAII wrapper over zlib's GZip file routines
5 
6 #include "Globals.h"
7 #include "File.h"
8 #include "GZipFile.h"
9 
10 
11 
12 
13 
14 Compression::Result GZipFile::ReadRestOfFile(const std::string & a_FileName)
15 {
16  InputFileStream File(a_FileName, InputFileStream::binary);
17  const std::string Input{ std::istreambuf_iterator<char>(File), std::istreambuf_iterator<char>() };
18  const ContiguousByteBufferView Data{ reinterpret_cast<const std::byte *>(Input.data()), Input.size() };
19 
20  return Compression::Extractor().ExtractGZip(Data);
21 }
22 
23 
24 
25 
26 
27 void GZipFile::Write(const std::string & a_FileName, ContiguousByteBufferView a_Contents)
28 {
29  OutputFileStream(a_FileName, OutputFileStream::binary) << Compression::Compressor().CompressGZip(a_Contents).GetStringView();
30 }
std::basic_string_view< std::byte > ContiguousByteBufferView
Definition: Globals.h:376
FileStream< std::ofstream > OutputFileStream
Definition: File.h:197
void Write(const std::string &a_FileName, ContiguousByteBufferView a_Contents)
Writes a_Contents into file, compressing it along the way.
Definition: GZipFile.cpp:27
Compression::Result ReadRestOfFile(const std::string &a_FileName)
Reads the rest of the file and returns the decompressed contents.
Definition: GZipFile.cpp:14
A wrapper for file streams that enables exceptions.
Definition: File.h:185
Contains the result of a compression or extraction operation.
std::string_view GetStringView() const
Returns a view (of type char) of the internal store.
Contains routines for data compression.
Result CompressGZip(ContiguousByteBufferView Input)
Contains routines for data extraction.
Result ExtractGZip(ContiguousByteBufferView Input)