#pragma once

#include "fs/IStreamSource.h"
#include "fs/Api.h"
#include "fs/zip/ZipPack.h"

namespace fs
{
class MemorySink;

class FS_API ZipFileStreamSource final : public IStreamSource
{
public:
	ZipFileStreamSource(tl::shared_ptr<ZipPack::ZipData> zipData, tl::unique_ref<zip_file> zipFile, uint64_t uncompressedSize) noexcept;

	ZipFileStreamSource(ZipFileStreamSource&&) noexcept = default;
	ZipFileStreamSource& operator=(ZipFileStreamSource&&) noexcept = default;

	~ZipFileStreamSource() override = default;

	tl::optional<Error> getLastError() const override;

	size_t read(tl::span<uint8_t> data) override;

	bool isEOS() const override;

	size_t getPreferredBufferSize() const override;

private:
	tl::shared_ptr<ZipPack::ZipData> m_zipData;
	tl::unique_ref<zip_file> m_zipFile;
	uint64_t m_uncompressedSize = 0;
	uint64_t m_offset = 0;
	mutable tl::optional<Error> m_optLastError;
};

}

