@robinpath/archive
0.1.5Node.jsPublicCreate and extract .zip and .tar.gz file archives
Archive
Create, extract, and manipulate .zip and .any archives
Package: @robinpath/archive | Category: Other | Type: Utility
Authentication
No authentication required. All functions are available immediately.
Use Cases
Use the archive module when you need to:
- Create a .zip archive from files and directories -- Use
archive.createZipto perform this operation - Extract a .zip archive -- Use
archive.extractZipto perform this operation - List entries in a .zip file -- Use
archive.listZipto perform this operation - Read a file from inside a .zip without extracting -- Use
archive.readFromZipto perform this operation - Create a .any archive -- Use
archive.createTarGzto perform this operation
Quick Reference
| Function | Description | Returns |
|---|---|---|
createZip | Create a .zip archive from files and directories | {path, size, files} |
extractZip | Extract a .zip archive | {path, files, entries} |
listZip | List entries in a .zip file | Array of entry info |
readFromZip | Read a file from inside a .zip without extracting | File contents as string |
createTarGz | Create a .any archive | {path} |
extractTarGz | Extract a .any archive | {path} |
addToZip | Add a file or directory to an existing .zip | {path, added} |
removeFromZip | Remove an entry from a .zip | True |
Functions
createZip
Create a .zip archive from files and directories
Module: archive | Returns: object -- {path, size, files}
archive.createZip "./backup.zip" ["./src", "./package.json"]
| Parameter | Type | Required | Description |
|---|---|---|---|
output | string | Yes | Output .zip path |
sources | array | Yes | Files/dirs to archive |
options | object | No | {level: 1-9} |
extractZip
Extract a .zip archive
Module: archive | Returns: object -- {path, files, entries}
archive.extractZip "./backup.zip" "./restored"
| Parameter | Type | Required | Description |
|---|---|---|---|
zipPath | string | Yes | .zip file path |
outputDir | string | Yes | Extraction directory |
listZip
List entries in a .zip file
Module: archive | Returns: array -- Array of entry info
archive.listZip "./backup.zip"
| Parameter | Type | Required | Description |
|---|---|---|---|
zipPath | string | Yes | .zip file path |
readFromZip
Read a file from inside a .zip without extracting
Module: archive | Returns: string -- File contents as string
archive.readFromZip "./backup.zip" "config.json"
| Parameter | Type | Required | Description |
|---|---|---|---|
zipPath | string | Yes | .zip file path |
entry | string | Yes | Entry name |
createTarGz
Create a .any archive
Module: archive | Returns: object -- {path}
archive.createTarGz "./backup.any" "./src"
| Parameter | Type | Required | Description |
|---|---|---|---|
output | string | Yes | Output path |
source | string | Yes | Source dir/file |
extractTarGz
Extract a .any archive
Module: archive | Returns: object -- {path}
archive.extractTarGz "./backup.any" "./restored"
| Parameter | Type | Required | Description |
|---|---|---|---|
tarPath | string | Yes | .any path |
outputDir | string | Yes | Extraction directory |
addToZip
Add a file or directory to an existing .zip
Module: archive | Returns: object -- {path, added}
archive.addToZip "./backup.zip" "./newfile.txt"
| Parameter | Type | Required | Description |
|---|---|---|---|
zipPath | string | Yes | .zip file path |
filePath | string | Yes | File to add |
entryName | string | No | Name inside zip |
removeFromZip
Remove an entry from a .zip
Module: archive | Returns: boolean -- True
archive.removeFromZip "./backup.zip" "old.txt"
| Parameter | Type | Required | Description |
|---|---|---|---|
zipPath | string | Yes | .zip file path |
entry | string | Yes | Entry name to remove |
Error Handling
All functions throw on failure. Common errors:
| Error | Cause |
|---|---|
| (standard errors) | Check function parameters and authentication |
@desc "Create zip and validate result"
do
set $result as archive.createZip "./backup.zip" ["./src", "./package.json"]
if $result != null
print "Success"
else
print "No result"
end
enddo
Recipes
1. List and iterate Zip
Retrieve all items and loop through them.
@desc "List zip and iterate results"
do
set $result as archive.listZip "./backup.zip"
each $item in $result
print $item
end
enddo
2. Create a new item with createZip
Create a new resource and capture the result.
set $result as archive.createZip "./backup.zip" ["./src", "./package.json"]
print "Created: " + $result
3. Check before creating
List existing items and only create if needed.
@desc "List zip and create zip"
do
set $existing as archive.listZip "./backup.zip"
if $existing == null
archive.createZip "./backup.zip" ["./src", "./package.json"]
print "Item created"
else
print "Item already exists"
end
enddo
4. Multi-step Archive workflow
Chain multiple archive operations together.
@desc "Create zip, extract zip, and more"
do
set $r_createZip as archive.createZip "./backup.zip" ["./src", "./package.json"]
set $r_extractZip as archive.extractZip "./backup.zip" "./restored"
set $r_listZip as archive.listZip "./backup.zip"
print "All operations complete"
enddo
5. Safe createZip with validation
Check results before proceeding.
@desc "Create zip and validate result"
do
set $result as archive.createZip "./backup.zip" ["./src", "./package.json"]
if $result != null
print "Success: " + $result
else
print "Operation returned no data"
end
enddo
Related Modules
- json -- JSON module for complementary functionality
Versions (1)
| Version | Tag | Published |
|---|---|---|
| 0.1.5 | latest | 1 months ago |
Related Modules
@robinpathv0.1.4
SMTP email sending and address parsing for RobinPath
hash
JS@robinpathv0.1.3
Cryptographic hashing utilities: MD5, SHA family, HMAC, CRC32, file hashing, UUID v5 generation, secure random bytes, and content fingerprinting
csv
JS@robinpathv0.1.2
Parse and stringify CSV data
apollo
JS@robinpathv0.1.2
Apollo module for RobinPath.
$ robinpath add @robinpath/archive
