libutil: remove makeDecompressionSink
the sole remaining user of this function can use makeDecompressionSource
instead, while making the sinkToSource in the caller unnecessary as well
Change-Id: I4258227b5dbbb735a75b477d8a57007bfca305e9
This commit is contained in:
parent
5587dbdcf0
commit
31478c810a
|
@ -32,23 +32,19 @@ void builtinFetchurl(const BasicDerivation & drv, const std::string & netrcData)
|
|||
|
||||
auto fetch = [&](const std::string & url) {
|
||||
|
||||
auto source = sinkToSource([&](Sink & sink) {
|
||||
|
||||
/* No need to do TLS verification, because we check the hash of
|
||||
the result anyway. */
|
||||
FileTransferRequest request(url);
|
||||
request.verifyTLS = false;
|
||||
|
||||
auto decompressor = makeDecompressionSink(
|
||||
unpack && mainUrl.ends_with(".xz") ? "xz" : "none", sink);
|
||||
fileTransfer->download(std::move(request))->drainInto(*decompressor);
|
||||
decompressor->finish();
|
||||
});
|
||||
auto raw = fileTransfer->download(std::move(request));
|
||||
auto decompressor = makeDecompressionSource(
|
||||
unpack && mainUrl.ends_with(".xz") ? "xz" : "none", *raw);
|
||||
|
||||
if (unpack)
|
||||
restorePath(storePath, *source);
|
||||
restorePath(storePath, *decompressor);
|
||||
else
|
||||
writeFile(storePath, *source);
|
||||
writeFile(storePath, *decompressor);
|
||||
|
||||
auto executable = drv.env.find("executable");
|
||||
if (executable != drv.env.end() && executable->second == "1") {
|
||||
|
|
|
@ -198,31 +198,6 @@ std::string decompress(const std::string & method, std::string_view in)
|
|||
return filter->drain();
|
||||
}
|
||||
|
||||
std::unique_ptr<FinishSink> makeDecompressionSink(const std::string & method, Sink & nextSink)
|
||||
{
|
||||
if (method == "none" || method == "")
|
||||
return std::make_unique<NoneSink>(nextSink);
|
||||
else if (method == "br")
|
||||
return sourceToSink([&](Source & source) {
|
||||
BrotliDecompressionSource wrapped{source};
|
||||
wrapped.drainInto(nextSink);
|
||||
// special handling because sourceToSink is screwy: try
|
||||
// to read the source one final time and fail when that
|
||||
// succeeds (to reject trailing garbage in input data).
|
||||
try {
|
||||
char buf;
|
||||
source(&buf, 1);
|
||||
throw Error("garbage at end of brotli stream detected");
|
||||
} catch (EndOfFile &) {
|
||||
}
|
||||
});
|
||||
else
|
||||
return sourceToSink([&](Source & source) {
|
||||
auto decompressionSource = std::make_unique<ArchiveDecompressionSource>(source);
|
||||
decompressionSource->drainInto(nextSink);
|
||||
});
|
||||
}
|
||||
|
||||
std::unique_ptr<Source> makeDecompressionSource(const std::string & method, Source & inner)
|
||||
{
|
||||
if (method == "none" || method == "") {
|
||||
|
|
|
@ -18,7 +18,6 @@ struct CompressionSink : BufferedSink, FinishSink
|
|||
|
||||
std::string decompress(const std::string & method, std::string_view in);
|
||||
|
||||
std::unique_ptr<FinishSink> makeDecompressionSink(const std::string & method, Sink & nextSink);
|
||||
std::unique_ptr<Source> makeDecompressionSource(const std::string & method, Source & inner);
|
||||
|
||||
std::string compress(const std::string & method, std::string_view in, const bool parallel = false, int level = -1);
|
||||
|
|
Loading…
Reference in a new issue