Skip to content

⌨ Send files over WIFI by scanning QR code in terminal

License

Notifications You must be signed in to change notification settings

imba-tjd/qrsend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

QR Send

This is a fork of https://github.com/sdushantha/qr-filetransfer.

  • I don't need upload and auth
  • I want a shorter exe name
  • I want a smaller QR code pattern
  • I don't need DEFLATED when make_archive because it's inefficient
  • I changed the code's filename so it makes no sense to keep upstream's commit history
  • When make_archive(), it's stored into the temp dir. So that it won't overwrite files that have the same name, and it's OK to shutdown ungracefully
  • Added a create_sendto() function to add qrsend.bat to SendTo context menu, though won't work when selecting muiltiple files
  • Added a monkey-patch to make http.server support Accept-Ranges: bytes
  • Added a read(shared) lock on file so that it won't be deleted while qrsend is open

Usage

pip install git+https://github.com/imba-tjd/qrsend  # pipx is preferred
qrsend file.txt/folder

Won't fix

  • In memory zip. The logic difference is too large. http.server works by reading local files. And according to the docs, ZipFile only accept path-like-obj now, rather than file-like-obj in Py2, let alone make_archive.

Details about ranges support

Originally proposed by https://bugs.python.org/issue42643 and python/cpython#24228 but it has some fatal errors.

  • not support no <range-end>
  • reads all remaining content into memory in a single call
  • logic error when computing the range of bytes

These has been fixed in my patch.

  1. I started by ignoring end_byte and let the client to guarantee not to excessive read. Tested that curl and FF works.
  2. I tried to use source.truncate(). But it turns out an io.UnsupportedOperation. The reason is that truncate will modify the actual file on disk, and mode 'r' protects that.
  3. wfile._sock.sendfile() is the perfect solution, except _sock isn't public.
    According to https://github.com/python/cpython/blob/main/Lib/socketserver.py, wfile is a file obj determined by wbufsize. When it == 0, wfile is _SocketWriter (added in https://bugs.python.org/issue26721), otherwise it's created by socket.makefile(). I think HTTPServer is not likely to change wbufsize, so it's ok to use _sock.

In the future, python/cpython#118949 is more likely to be merged.

About

⌨ Send files over WIFI by scanning QR code in terminal

Resources

License

Stars

Watchers

Forks

Languages