Skip to content

Commit ca582f5

Browse files
chore: autopublish 2024-10-14T16:04:20Z
1 parent f3bf00b commit ca582f5

File tree

1 file changed

+134
-0
lines changed

1 file changed

+134
-0
lines changed

Diff for: docs/library/ziputils.md

+134
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
# ziputils
2+
3+
Functions for unzipping files. (Future may include zipping as well.)
4+
5+
Dependencies:
6+
7+
- Windows users must have `7z` installed. You can download it [here](https://www.7-zip.org/).
8+
- MacOS users must have `unzip` and `gunzip`, but these are usually installed with the OS.
9+
10+
Pay careful attention to the comments about how strings are encoded. They are either encoded
11+
**platform** or **utf8**. On macOS, platform encoding is always utf8, but on Windows it can
12+
be any number of encodings depending on the locale settings and version of Windows. You can use
13+
`luaosutils.text` to convert them back and forth. Both `luaosutils.process.execute`
14+
requires platform encoding as do `lfs` and all built-in Lua `io` functions.
15+
16+
Note that many functions require later versions of RGP Lua that include `luaosutils`
17+
and/or `lfs`. But the these dependencies are embedded in each function so that any version
18+
of Lua for Finale can at least load the library.
19+
20+
## Functions
21+
22+
- [calc_rmdir_command(path_to_remove)](#calc_rmdir_command)
23+
- [calc_delete_file_command(path_to_remove)](#calc_delete_file_command)
24+
- [calc_temp_output_path(archive_path)](#calc_temp_output_path)
25+
- [calc_gunzip_command(archive_path)](#calc_gunzip_command)
26+
- [calc_is_gzip(buffer)](#calc_is_gzip)
27+
28+
### calc_rmdir_command
29+
30+
```lua
31+
ziputils.calc_rmdir_command(path_to_remove)
32+
```
33+
34+
[View source](https://github.com/finale-lua/lua-scripts/tree/refs/heads/master/src/library/ziputils.lua#L49)
35+
36+
Returns the platform-dependent command to remove a directory. It can be passed
37+
to `luaosutils.process.execute`.
38+
39+
**WARNING** The command, if executed, permanently deletes the contents of the directory.
40+
You would normally call this on the temporary directory name from `calc_temp_output_path`.
41+
But it works on any directory.
42+
43+
| Input | Type | Description |
44+
| ----- | ---- | ----------- |
45+
| `path_to_remove` | `string` | platform-encoded path of directory to remove. |
46+
47+
| Return type | Description |
48+
| ----------- | ----------- |
49+
| `string` | platform-encoded command string to execute. |
50+
51+
### calc_delete_file_command
52+
53+
```lua
54+
ziputils.calc_delete_file_command(path_to_remove)
55+
```
56+
57+
[View source](https://github.com/finale-lua/lua-scripts/tree/refs/heads/master/src/library/ziputils.lua#L66)
58+
59+
Returns the platform-dependent command to delete a file. It can be passed
60+
to `luaosutils.process.execute`.
61+
62+
**WARNING** The command, if executed, permanently deletes the file.
63+
You would normally call this on the temporary directory name from `calc_temp_output_path`.
64+
But it works on any directory.
65+
66+
| Input | Type | Description |
67+
| ----- | ---- | ----------- |
68+
| `path_to_remove` | `string` | platform-encoded path of directory to remove. |
69+
70+
| Return type | Description |
71+
| ----------- | ----------- |
72+
| `string` | platform-encoded command string to execute. |
73+
74+
### calc_temp_output_path
75+
76+
```lua
77+
ziputils.calc_temp_output_path(archive_path)
78+
```
79+
80+
[View source](https://github.com/finale-lua/lua-scripts/tree/refs/heads/master/src/library/ziputils.lua#L86)
81+
82+
Returns a path that can be used as a temporary target for unzipping. The caller may create it
83+
either as a file or a directory, because it is guaranteed not to exist when it is returned and it does
84+
not have a terminating path delimiter. Also returns a platform-dependent unzip command that can be
85+
passed to `luaosutils.process.execute` to unzip the input archive into the temporary name as a directory.
86+
The command may not be compatible with `os.execute`.
87+
88+
This function requires `luaosutils`.
89+
90+
| Input | Type | Description |
91+
| ----- | ---- | ----------- |
92+
| `archive_path` (optional) | `string` | platform-encoded filepath to the zip archive that is included in the zip command. |
93+
94+
| Return type | Description |
95+
| ----------- | ----------- |
96+
| `string` | platform-encoded temporary path generated by the system. |
97+
| `string` | platform-encoded unzip command that can be used to unzip a multifile archived directory structure into the temporary path. |
98+
99+
### calc_gunzip_command
100+
101+
```lua
102+
ziputils.calc_gunzip_command(archive_path)
103+
```
104+
105+
[View source](https://github.com/finale-lua/lua-scripts/tree/refs/heads/master/src/library/ziputils.lua#L118)
106+
107+
Returns the platform-dependent command to gunzip a file. It can be passed
108+
to `luaosutils.process.execute`, which will then return the text directly.
109+
110+
| Input | Type | Description |
111+
| ----- | ---- | ----------- |
112+
| `archive_path` | `string` | platform-encoded path of source gzip archive. |
113+
114+
| Return type | Description |
115+
| ----------- | ----------- |
116+
| `string` | platform-encoded command string to execute. |
117+
118+
### calc_is_gzip
119+
120+
```lua
121+
ziputils.calc_is_gzip(buffer)
122+
```
123+
124+
[View source](https://github.com/finale-lua/lua-scripts/tree/refs/heads/master/src/library/ziputils.lua#L134)
125+
126+
Detects if an input buffer is a gzip archive. Sometimes, Finale gzips the internal EnigmaXML document.
127+
128+
| Input | Type | Description |
129+
| ----- | ---- | ----------- |
130+
| `buffer` | `string` | binary data to check if it is a gzip archive |
131+
132+
| Return type | Description |
133+
| ----------- | ----------- |
134+
| `boolean` | true if the buffer is a gzip archive |

0 commit comments

Comments
 (0)