aboutsummaryrefslogtreecommitdiff
path: root/src/zenserver/frontend/zipfs.h
blob: c6acf73346023baf71d657f012d527afe9133df3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// Copyright Epic Games, Inc. All Rights Reserved.

#pragma once

#include <zencore/iobuffer.h>
#include <zencore/thread.h>

#include <unordered_map>

namespace zen {

class ZipFs
{
public:
	explicit ZipFs(IoBuffer&& Buffer);

	IoBuffer GetFile(const std::string_view& FileName) const;

private:
	struct FileItem
	{
		MemoryView View;  // Initially points to LFH (size=0); resolved to file data on first access
		uint32_t   CompressedSize	 = 0;
		uint32_t   UncompressedSize	 = 0;
		uint16_t   CompressionMethod = 0;
		IoBuffer   DecompressedData;  // Owns decompressed buffer for deflate entries
	};

	using FileMap = std::unordered_map<std::string_view, FileItem>;
	mutable RwLock m_FilesLock;
	FileMap mutable m_Files;
	IoBuffer m_Buffer;
};

}  // namespace zen