Modules@robinpath/archive
archive

@robinpath/archive

0.1.5Node.jsPublic

Create 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.createZip to perform this operation
  • Extract a .zip archive -- Use archive.extractZip to perform this operation
  • List entries in a .zip file -- Use archive.listZip to perform this operation
  • Read a file from inside a .zip without extracting -- Use archive.readFromZip to perform this operation
  • Create a .any archive -- Use archive.createTarGz to perform this operation

Quick Reference

FunctionDescriptionReturns
createZipCreate a .zip archive from files and directories{path, size, files}
extractZipExtract a .zip archive{path, files, entries}
listZipList entries in a .zip fileArray of entry info
readFromZipRead a file from inside a .zip without extractingFile contents as string
createTarGzCreate a .any archive{path}
extractTarGzExtract a .any archive{path}
addToZipAdd a file or directory to an existing .zip{path, added}
removeFromZipRemove an entry from a .zipTrue

Functions

createZip

Create a .zip archive from files and directories

Module: archive | Returns: object -- {path, size, files}

archive.createZip "./backup.zip" ["./src", "./package.json"]
ParameterTypeRequiredDescription
outputstringYesOutput .zip path
sourcesarrayYesFiles/dirs to archive
optionsobjectNo{level: 1-9}

extractZip

Extract a .zip archive

Module: archive | Returns: object -- {path, files, entries}

archive.extractZip "./backup.zip" "./restored"
ParameterTypeRequiredDescription
zipPathstringYes.zip file path
outputDirstringYesExtraction directory

listZip

List entries in a .zip file

Module: archive | Returns: array -- Array of entry info

archive.listZip "./backup.zip"
ParameterTypeRequiredDescription
zipPathstringYes.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"
ParameterTypeRequiredDescription
zipPathstringYes.zip file path
entrystringYesEntry name

createTarGz

Create a .any archive

Module: archive | Returns: object -- {path}

archive.createTarGz "./backup.any" "./src"
ParameterTypeRequiredDescription
outputstringYesOutput path
sourcestringYesSource dir/file

extractTarGz

Extract a .any archive

Module: archive | Returns: object -- {path}

archive.extractTarGz "./backup.any" "./restored"
ParameterTypeRequiredDescription
tarPathstringYes.any path
outputDirstringYesExtraction directory

addToZip

Add a file or directory to an existing .zip

Module: archive | Returns: object -- {path, added}

archive.addToZip "./backup.zip" "./newfile.txt"
ParameterTypeRequiredDescription
zipPathstringYes.zip file path
filePathstringYesFile to add
entryNamestringNoName inside zip

removeFromZip

Remove an entry from a .zip

Module: archive | Returns: boolean -- True

archive.removeFromZip "./backup.zip" "old.txt"
ParameterTypeRequiredDescription
zipPathstringYes.zip file path
entrystringYesEntry name to remove

Error Handling

All functions throw on failure. Common errors:

ErrorCause
(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)

VersionTagPublished
0.1.5latest1 months ago
Install
$ robinpath add @robinpath/archive

Collaborators

Dumitru Balaban
Dumitru Balaban
@dumitru
View all @robinpath modules
Version0.1.5
LicenseMIT
Unpacked Size8.0 KB
Versions1
Weekly Downloads26
Total Downloads26
Stars0
Last Publish1 months ago
Created1 months ago

Keywords

Category

utilities