Skip to content

Commit

Permalink
fix: error thrown on large files (#184)
Browse files Browse the repository at this point in the history
Codeium.nvim throws error on large files because curl fails to do
the request when using --data-raw with:

`E2BIG: argument list too long`.

This fixes the problem by writing the data to a temporary file
and passing it to curl as a binary file with --data-binary.
  • Loading branch information
brunolpsousa authored May 3, 2024
1 parent ace6ee3 commit d3b88eb
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion lua/codeium/io.lua
Original file line number Diff line number Diff line change
Expand Up @@ -399,16 +399,27 @@ function M.download(url, path, callback)
end

function M.post(url, params)
local tmpfname = os.tmpname()

if type(params.body) == "table" then
local f = io.open(tmpfname, 'w+')
if f == nil then
log.error('Cannot open temporary message file: ' .. tmpfname)
return
end
f:write(vim.fn.json_encode(params.body))
f:close()

params.headers = params.headers or {}
params.headers["content-type"] = params.headers["content-type"] or "application/json"
params.compressed = false
params.body = vim.fn.json_encode(params.body)
params.body = tmpfname
end

local cb = vim.schedule_wrap(params.callback)

params.callback = function(out, _)
os.remove(tmpfname)
if out.exit ~= 0 then
cb(nil, {
code = out.exit,
Expand Down

0 comments on commit d3b88eb

Please sign in to comment.