//
// Copyright (C) 2025 The Android Open Source Project
//
// Licensed 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 <stddef.h>

#include "cuttlefish/io/io.h"
#include "cuttlefish/result/result_type.h"

namespace cuttlefish {

// Moves data from the Reader to the Writer, without doing additional seeking on
// either. This means if either has seek pointers set somewhere in the middle of
// the data, reading and writing starts from that point.
Result<void> Copy(Reader&, Writer&, size_t buffer_size = 1 << 26);

// Moves data from the Reader to the WriterSeeker. Uses heuristics to detect
// large chunks of zeroes, and performs forward seeks on the output rather than
// writing the zeroes.
//
// This is helpful for writing large files to the filesystem, as it can use the
// linux-sparse mechanism to not fully allocate blocks.
Result<void> SparseCopy(Reader&, WriterSeeker&, size_t buffer_size = 1 << 26);

}  // namespace cuttlefish
