Skip to content

Issue in Res:sendFile() #10

@DTJF

Description

@DTJF

I've an issue in function Res:sendFile() in the local function doSend(): When the file length is a multiple of 512 (1024, 1536, 2048, ...) the function fails at the end of the file, since buf is nil in self._skt:send(buf). Here's how I fixed it:

  print('* Sending ', filename)
  local pos, fin = 0, nil
  local function doSend()
    file.open(filename, 'r')
    if file.seek('set', pos) == nil then
      fin = 1
    else
      local buf = file.read(512)
      pos = pos + 512
      if buf == nil then
        fin = 1
      else
        self._skt:send(buf)
      end
    end
    file.close()
    if fin then
      self:close()
      print('* Finished ', filename)
    end
  end

Great project, thanks for sharing!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions