
---@alias ltn12_source fun(): string?, string?
---@alias ltn12_sink fun(chunk:string?, err?:string): boolean?, string?
---@alias ltn12_filter fun(chunk:string?, ...): string?
---@alias ltn12_pump_step fun(src:ltn12_source, snk:ltn12_sink): boolean?, string?

---@class ltn12_filter_module*
local ltn12_filter_module = {}

---@class ltn12_source_module*
local ltn12_source_module = {}

---@class ltn12_sink_module*
local ltn12_sink_module = {}

---@class ltn12_pump_module*
local ltn12_pump_module = {}

---@class ltn12*
---@field BLOCKSIZE integer Default block size.
---@field _VERSION string Module version.
---@field filter ltn12_filter_module* Filter factory.
---@field source ltn12_source_module* source factory.
---@field sink ltn12_sink_module* sink factory.
---@field pump ltn12_pump_module* pump tool.
---@type ltn12*
local M = {}

M.BLOCKSIZE = 2048
M._VERSION = nil
M.filter = ltn12_filter_module
M.source = ltn12_source_module
M.sink = ltn12_sink_module
M.pump = ltn12_pump_module

--- Create a stateful filter.
---@param low function The underlying filter function.
---@param ctx? any context.
---@param extra? any Additional parameters.
---@return ltn12_filter filter filter.
function ltn12_filter_module.cycle(low, ctx, extra) end

--- Concatenate multiple filters.
---@param ... ltn12_filter filter.
---@return ltn12_filter filter Filters in series.
function ltn12_filter_module.chain(...) end

--- Empty source.
---@return ltn12_source source source function.
function ltn12_source_module.empty() end

--- Always returns the wrong source.
---@param err string error message.
---@return ltn12_source source source function.
function ltn12_source_module.error(err) end

--- Create a source from a file handle.
---@param handle file* File handle.
---@param io_err? string Error when opening file.
---@return ltn12_source source source function.
function ltn12_source_module.file(handle, io_err) end

--- Simplify source error handling.
---@param src ltn12_source source function.
---@return ltn12_source source source function.
function ltn12_source_module.simplify(src) end

--- Create a source from a string.
---@param value string String.
---@return ltn12_source source source function.
function ltn12_source_module.string(value) end

--- Create source from table.
---@param values string[] List of strings.
---@return ltn12_source source source function.
function ltn12_source_module.table(values) end

--- Create a source that rolls back one chunk.
---@param src ltn12_source source function.
---@return fun(chunk?:string):string?, string? source source function.
function ltn12_source_module.rewind(src) end

--- Connect the source output to the filter.
---@param src ltn12_source source function.
---@param filter ltn12_filter filter.
---@param ... any Filter parameters.
---@return ltn12_source source source function.
function ltn12_source_module.chain(src, filter, ...) end

--- Concatenate multiple sources.
---@param ... ltn12_source source function.
---@return ltn12_source source source function.
function ltn12_source_module.cat(...) end

--- Write output to table.
---@param values? string[] Receive list.
---@return ltn12_sink sink sink function.
---@return string[] values Receive list.
function ltn12_sink_module.table(values) end

--- Writes output to a file handle.
---@param handle file* File handle.
---@param io_err? string Error when opening file.
---@return ltn12_sink sink sink function.
function ltn12_sink_module.file(handle, io_err) end

--- Simplify sink error handling.
---@param snk ltn12_sink sink function.
---@return ltn12_sink sink sink function.
function ltn12_sink_module.simplify(snk) end

--- Discard all output.
---@return ltn12_sink sink sink function.
function ltn12_sink_module.null() end

--- Always returns the wrong sink.
---@param err string error message.
---@return ltn12_sink sink sink function.
function ltn12_sink_module.error(err) end

--- Connect the filter output to the sink.
---@param filter ltn12_filter filter.
---@param snk ltn12_sink sink function.
---@param ... any Filter parameters.
---@return ltn12_sink sink sink function.
function ltn12_sink_module.chain(filter, snk, ...) end

--- Perform a one-step pump.
---@param src ltn12_source source function.
---@param snk ltn12_sink sink function.
---@return boolean? ok Whether to continue.
---@return string? errMsg error message.
function ltn12_pump_module.step(src, snk) end

--- Continue pumping until source ends.
---@param src ltn12_source source function.
---@param snk ltn12_sink sink function.
---@param step? ltn12_pump_step Custom step.
---@return boolean? ok Whether it is successful or not.
---@return string? errMsg error message.
function ltn12_pump_module.all(src, snk, step) end

return M
