adamdebreceni commented on a change in pull request #1224:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1224#discussion_r778085157
##########
File path: extensions/libarchive/CompressContent.cpp
##########
@@ -176,9 +177,36 @@ void CompressContent::processFlowFile(const
std::shared_ptr<core::FlowFile>& flo
std::shared_ptr<core::FlowFile> result = session->create(flowFile);
bool success = false;
if (encapsulateInTar_) {
- CompressContent::WriteCallback callback(compressMode_, compressLevel_,
compressFormat, flowFile, session);
- session->write(result, &callback);
- success = callback.status_ >= 0;
+ std::function<int64_t(const std::shared_ptr<io::InputStream>&, const
std::shared_ptr<io::OutputStream>&)> transformer;
+
+ if (compressMode_ == CompressionMode::Compress) {
+ std::string filename;
+ flowFile->getAttribute(core::SpecialFlowAttribute::FILENAME, filename);
+ transformer = [&, filename] (const std::shared_ptr<io::InputStream>& in,
const std::shared_ptr<io::OutputStream>& out) -> int64_t {
+ io::WriteArchiveStreamImpl compressor(compressLevel_, compressFormat,
out);
+ if (!compressor.newEntry({filename, in->size()})) {
+ return -1;
+ }
+ return internal::pipe(in.get(), &compressor);
+ };
+ } else {
+ transformer = [&] (const std::shared_ptr<io::InputStream>& in, const
std::shared_ptr<io::OutputStream>& out) -> int64_t {
+ io::ReadArchiveStreamImpl decompressor(in);
+ if (!decompressor.nextEntry()) {
+ return -1;
+ }
+ return internal::pipe(&decompressor, out.get());
+ };
+ }
+ session->write(result, FunctionOutputStreamCallback([&] (const auto& out) {
+ return session->read(flowFile, FunctionInputStreamCallback([&] (const
auto& in) {
+ return transformer(in, out);
+ }));
+ }));
+ // TODO(adebreceni): previous attempt to handle a malformed archive were
in vain
Review comment:
created ticked and added link as comment
##########
File path: extensions/libarchive/ReadArchiveStream.h
##########
@@ -0,0 +1,91 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <memory>
+#include <utility>
+
+#include "io/OutputStream.h"
+#include "io/ArchiveStream.h"
+#include "core/logging/LoggerConfiguration.h"
+
+#include "archive_entry.h"
+#include "archive.h"
+
+namespace org::apache::nifi::minifi::io {
+
+class ReadArchiveStreamImpl : public ReadArchiveStream {
+ struct archive_read_deleter {
+ int operator()(struct archive* ptr) const {
+ return archive_read_free(ptr);
+ }
+ };
+ using archive_ptr = std::unique_ptr<struct archive, archive_read_deleter>;
+
+ class BufferedReader {
+ public:
+ explicit BufferedReader(std::shared_ptr<InputStream> input) :
input_(std::move(input)) {}
+
+ std::optional<gsl::span<const uint8_t>> readChunk() {
+ size_t result = input_->read(buffer_.data(), buffer_.size());
+ if (io::isError(result)) {
+ return std::nullopt;
+ }
+ return gsl::span<const uint8_t>(buffer_.data(), result);
+ }
+
+ private:
+ std::shared_ptr<InputStream> input_;
+ std::array<uint8_t, 4096> buffer_;
+ };
+
+ archive_ptr createReadArchive();
+
+ public:
+ explicit ReadArchiveStreamImpl(std::shared_ptr<InputStream> input) :
reader_(std::move(input)) {
+ arch_ = createReadArchive();
+ }
+
+ std::shared_ptr<InputStream> input_;
+ std::shared_ptr<core::logging::Logger> logger_ =
core::logging::LoggerFactory<ReadArchiveStream>::getLogger();
+ BufferedReader reader_;
+ archive_ptr arch_;
Review comment:
made them private
##########
File path: extensions/libarchive/ReadArchiveStream.h
##########
@@ -0,0 +1,91 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <memory>
+#include <utility>
+
+#include "io/OutputStream.h"
+#include "io/ArchiveStream.h"
+#include "core/logging/LoggerConfiguration.h"
+
+#include "archive_entry.h"
+#include "archive.h"
+
+namespace org::apache::nifi::minifi::io {
+
+class ReadArchiveStreamImpl : public ReadArchiveStream {
+ struct archive_read_deleter {
+ int operator()(struct archive* ptr) const {
+ return archive_read_free(ptr);
+ }
+ };
+ using archive_ptr = std::unique_ptr<struct archive, archive_read_deleter>;
+
+ class BufferedReader {
+ public:
+ explicit BufferedReader(std::shared_ptr<InputStream> input) :
input_(std::move(input)) {}
+
+ std::optional<gsl::span<const uint8_t>> readChunk() {
+ size_t result = input_->read(buffer_.data(), buffer_.size());
+ if (io::isError(result)) {
+ return std::nullopt;
+ }
+ return gsl::span<const uint8_t>(buffer_.data(), result);
+ }
+
+ private:
+ std::shared_ptr<InputStream> input_;
+ std::array<uint8_t, 4096> buffer_;
+ };
+
+ archive_ptr createReadArchive();
+
+ public:
+ explicit ReadArchiveStreamImpl(std::shared_ptr<InputStream> input) :
reader_(std::move(input)) {
+ arch_ = createReadArchive();
+ }
+
+ std::shared_ptr<InputStream> input_;
Review comment:
removed
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]