2020-10-02 05:22:40 +00:00
|
|
|
/*
|
2021-09-01 02:32:46 +00:00
|
|
|
* Copyright (c) 2020, Peter Elliott <pelliott@serenityos.org>
|
2021-04-22 20:40:43 +00:00
|
|
|
* Copyright (c) 2021, Idan Horowitz <idan.horowitz@serenityos.org>
|
2020-10-02 05:22:40 +00:00
|
|
|
*
|
2021-04-22 08:24:48 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-10-02 05:22:40 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <AK/Span.h>
|
|
|
|
#include <AK/Stream.h>
|
2021-03-18 14:22:05 +00:00
|
|
|
#include <LibArchive/Tar.h>
|
2020-10-02 05:22:40 +00:00
|
|
|
|
2021-03-18 14:22:05 +00:00
|
|
|
namespace Archive {
|
2020-10-02 05:22:40 +00:00
|
|
|
|
2021-03-12 23:40:04 +00:00
|
|
|
class TarInputStream;
|
2020-10-02 05:22:40 +00:00
|
|
|
|
|
|
|
class TarFileStream : public InputStream {
|
|
|
|
public:
|
|
|
|
size_t read(Bytes) override;
|
|
|
|
bool unreliable_eof() const override;
|
|
|
|
|
|
|
|
bool read_or_error(Bytes) override;
|
|
|
|
bool discard_or_error(size_t count) override;
|
|
|
|
|
|
|
|
private:
|
2021-03-12 23:40:04 +00:00
|
|
|
TarFileStream(TarInputStream& stream);
|
|
|
|
TarInputStream& m_tar_stream;
|
2020-10-02 05:22:40 +00:00
|
|
|
int m_generation;
|
|
|
|
|
2021-03-12 23:40:04 +00:00
|
|
|
friend class TarInputStream;
|
2020-10-02 05:22:40 +00:00
|
|
|
};
|
|
|
|
|
2021-03-12 23:40:04 +00:00
|
|
|
class TarInputStream {
|
2020-10-02 05:22:40 +00:00
|
|
|
public:
|
2021-03-12 23:40:04 +00:00
|
|
|
TarInputStream(InputStream&);
|
2020-10-02 05:22:40 +00:00
|
|
|
void advance();
|
|
|
|
bool finished() const { return m_finished; }
|
2020-10-03 18:59:41 +00:00
|
|
|
bool valid() const;
|
2021-03-18 14:22:05 +00:00
|
|
|
const TarFileHeader& header() const { return m_header; }
|
2020-10-02 05:22:40 +00:00
|
|
|
TarFileStream file_contents();
|
|
|
|
|
|
|
|
private:
|
2021-03-18 14:22:05 +00:00
|
|
|
TarFileHeader m_header;
|
2020-10-02 05:22:40 +00:00
|
|
|
InputStream& m_stream;
|
|
|
|
unsigned long m_file_offset { 0 };
|
|
|
|
int m_generation { 0 };
|
|
|
|
bool m_finished { false };
|
|
|
|
|
|
|
|
friend class TarFileStream;
|
|
|
|
};
|
|
|
|
|
2021-03-12 23:40:04 +00:00
|
|
|
class TarOutputStream {
|
|
|
|
public:
|
|
|
|
TarOutputStream(OutputStream&);
|
2021-11-11 00:06:34 +00:00
|
|
|
void add_file(const String& path, mode_t, ReadonlyBytes);
|
2021-03-12 23:40:04 +00:00
|
|
|
void add_directory(const String& path, mode_t);
|
|
|
|
void finish();
|
|
|
|
|
|
|
|
private:
|
|
|
|
OutputStream& m_stream;
|
|
|
|
bool m_finished { false };
|
|
|
|
|
|
|
|
friend class TarFileStream;
|
|
|
|
};
|
|
|
|
|
2020-10-02 05:22:40 +00:00
|
|
|
}
|