|
@@ -1,10 +1,12 @@
|
|
|
/*
|
|
|
* Copyright (c) 2020, Peter Elliott <pelliott@serenityos.org>
|
|
|
* Copyright (c) 2021, Idan Horowitz <idan.horowitz@serenityos.org>
|
|
|
+ * Copyright (c) 2022, the SerenityOS developers.
|
|
|
*
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
*/
|
|
|
|
|
|
+#include <AK/Array.h>
|
|
|
#include <LibArchive/TarStream.h>
|
|
|
#include <string.h>
|
|
|
|
|
@@ -155,22 +157,22 @@ void TarOutputStream::add_file(const String& path, mode_t mode, ReadonlyBytes by
|
|
|
header.set_magic(gnu_magic);
|
|
|
header.set_version(gnu_version);
|
|
|
header.calculate_checksum();
|
|
|
- VERIFY(m_stream.write_or_error(Bytes { &header, sizeof(header) }));
|
|
|
- u8 padding[block_size] = { 0 };
|
|
|
- VERIFY(m_stream.write_or_error(Bytes { &padding, block_size - sizeof(header) }));
|
|
|
+ VERIFY(m_stream.write_or_error(ReadonlyBytes { &header, sizeof(header) }));
|
|
|
+ constexpr Array<u8, block_size> padding { 0 };
|
|
|
+ VERIFY(m_stream.write_or_error(ReadonlyBytes { &padding, block_size - sizeof(header) }));
|
|
|
size_t n_written = 0;
|
|
|
while (n_written < bytes.size()) {
|
|
|
n_written += m_stream.write(bytes.slice(n_written, min(bytes.size() - n_written, block_size)));
|
|
|
}
|
|
|
- VERIFY(m_stream.write_or_error(Bytes { &padding, block_size - (n_written % block_size) }));
|
|
|
+ VERIFY(m_stream.write_or_error(ReadonlyBytes { &padding, block_size - (n_written % block_size) }));
|
|
|
}
|
|
|
|
|
|
void TarOutputStream::finish()
|
|
|
{
|
|
|
VERIFY(!m_finished);
|
|
|
- u8 padding[block_size] = { 0 };
|
|
|
- m_stream.write_or_error(Bytes { &padding, block_size }); // 2 empty records that are used to signify the end of the archive
|
|
|
- m_stream.write_or_error(Bytes { &padding, block_size });
|
|
|
+ constexpr Array<u8, block_size> padding { 0 };
|
|
|
+ m_stream.write_or_error(ReadonlyBytes { &padding, block_size }); // 2 empty records that are used to signify the end of the archive
|
|
|
+ m_stream.write_or_error(ReadonlyBytes { &padding, block_size });
|
|
|
m_finished = true;
|
|
|
}
|
|
|
|