-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.fer
46 lines (43 loc) · 1.4 KB
/
test.fer
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
let fs = import('std/fs');
let vec = import('std/vec');
let stat = import('std/stat');
let ar = import('archive/archive');
let bytebuffer = import('std/bytebuffer');
# libarchive zstd format doesn't seem to be working correctly on Android (10)
let zstwriter = ar.newArchive(ar.OPEN_WRITE);
zstwriter.addFilter(ar.FILTER_ZSTD);
zstwriter.setFormat(ar.FORMAT_TAR_PAX_RESTRICTED);
zstwriter.open('test.tar.zst');
zstwriter.addFile('README.md');
zstwriter.addFile('LICENSE');
zstwriter.close();
let zstreader = ar.newArchive(ar.OPEN_READ);
zstreader.addFilter(ar.FILTER_ZSTD);
zstreader.setFormat(ar.FORMAT_TAR_PAX_RESTRICTED);
zstreader.open('test.tar.zst');
zstreader.extract();
zstreader.close();
# equivalent to https://github.com/libarchive/libarchive/wiki/Examples#a-basic-write-example
let files = vec.new('README.md', 'LICENSE');
let bb = bytebuffer.new(8192);
let gzwriter = ar.newArchive(ar.OPEN_WRITE);
gzwriter.addFilter(ar.FILTER_GZIP);
gzwriter.setFormat(ar.FORMAT_TAR_PAX_RESTRICTED);
gzwriter.open('test.tar.gz');
let entry = ar.newEntry();
for file in files.each() {
let stat = stat.stat(file);
entry.setPathname(file);
entry.setSize(stat.size);
entry.setFiletype(stat.getArchiveEntryFiletype());
entry.setPerm(stat.mode);
gzwriter.writeHeader(entry);
let fd = fs.fdOpen(file);
let len = 0;
while (len = fs.fdRead(fd, bb)) > 0 {
gzwriter.writeData(bb);
}
fs.fdClose(fd);
entry.clear();
}
gzwriter.close();