How do you specify filenames within a zip when creating it on the command line from a pipe?

后端 未结 6 1847
面向向阳花
面向向阳花 2020-12-13 19:46

I\'m trying to create a zip file from file contents which are being piped in, e.g.

mysql [params and query] | zip -q output.zip -

This writ

6条回答
  •  不思量自难忘°
    2020-12-13 20:03

    mysql [params and query] | python3 -c "import sys as s,os,zipfile as m;z=m.ZipFile(os.fdopen(s.stdout.fileno(),'wb'),'w');z.writestr(s.argv[1],s.stdin.read());z.close()" 'filename.sql' > output.zip
    

    Python 3.5 added support for writing to unseekable streams.

    It's not pretty but works.

提交回复
热议问题