zip - Simplest format to archive a directory
问题描述
I have a script that needs to work on multiple platforms and machines. Some of those machines don't have any available archiving software (e.g. zip, tar). I can't download any software onto these machines.
The script creates a directory containing output files. I need to package all those files into a single file so i can download it easily.
What is the simplest possible archiving format to implement, so I can easily roll my own impl in the script. It doesn't have to support compression.
I could make up something ad-hoc, e.g.
file1 base64EncodedContents
dir1/file1 base64EncodedContents
etc.
However if one already exists then that will save me having to roll my own packing and unpacking, only packing, which would be nice. Bonus points if it's zip compatible, so that I can try zipping it with compression if possible, and them impl my own without compression otherwise, and not have to worry about which it is on the other side.
解决方案
The tar archive format is extremely simple - simple enough that I was able to implement a tar archiver in powershell in a couple of hours.
It consists of a sequence of file header, file data, file header, file data etc.
The header is pure ascii, so doesn't require any bit manipulation - you can literally append strings. Once you've written the header, you then append the file bytes, and pad it with nil chars till it's a multiple of 512 bytes. You then repeat for the next file.
Wikipedia has more details on the exact format: https://en.wikipedia.org/wiki/Tar_(computing).
推荐阅读
- java - 通过远程 JVM 在 Intellij IDEA 中进行 Maven 调试不会通过 Step Over/Into btns 遍历代码
- sorting - 苏禄智能字段类型排序顺序?
- react-native - React-Native:文本在不同手机中呈现不同
- kubernetes - GKE 单 ip 负载平衡器重叠端口
- python - 为什么在使用 pymysql 时必须重新连接数据库才能获取更新的数据库数据?
- python - 在 Api URL 中如何在 Django 中增加页码
- javascript - 使用节点 js 过滤对象键和值
- javascript - bootstrap 4手风琴在角度项目中动态加载
- google-cloud-platform - 使用 DataflowTempleOperator 的 Composer Dataflow 作业错误
- r - 从 Rstudio 连接到 SQL 数据库时出错