File
File objects are returned by
Archive.open() and
Entry.open() and provide methods for reading from
or writing to files within a ZIP archive. Entry metadata such as size and
Unix mode is available on Entry rather than File.
Methods
read size
Reads data from the file.
Availability: Read mode only
Parameters
| Name | Type | Description |
|---|---|---|
size |
Int |
Maximum number of bytes to read |
Returns
Example
open "archive.zip" do |archive|
archive.open "document.txt" do |file|
let data = file.read 4096
echo "Read $(data.len) bytes"
# Convert to string if text
let text = Str data
echo text
Error: Raises a runtime error if called on a file opened in write mode.
write data
Writes data to the file.
Availability: Write mode only
Parameters
| Name | Type | Description |
|---|---|---|
data |
Bin or Str |
Data to write |
Example
open "output.zip" "w" do |archive|
archive.open "data.bin" do |file|
file.write "Hello, World!"
file.write b"\x00\x01\x02\x03"
Error: Raises a runtime error if called on a file opened in read mode.
close()
Closes the file.