Zip

The Zip extension allows you to read, create and edit .zip format files, including Scratch project and sprite files (.sb3, .sprite3).

The extension handles archives entirely in-memory; to interact with the file system you'll have to use it alongside other extensions, like Files. In-memory zip files will be referred to as archives in this documentation (and in the blocks).

Paths

Most blocks in this extension work with a path format:

Archive management blocks

Blocks for creating and saving archives.


create empty archive named [archive] :: #a49a3a

Creates and opens an empty archive with nothing in it. The name is used for dealing with multiple archives at time; it can be any non-empty string and does not have to be the archive's filename.


open zip from (URL v) [https://extensions.turbowarp.org] named [archive] :: #a49a3a

Opens a .zip (or .sb3 or .sprite3...) file.

The type can be one of the following:

The name is used for dealing with multiple archives at time; it can be any non-empty string and does not have to be the archive's filename.

If the file is not of zip format (e.g RAR or 7z) or is password-protected, it won't be opened. Make sure to check if it loaded successfully with the error opening archive? block.


(output zip type (data: URI v) compression level (6 v) :: #a49a3a)

Saves the current archive into a zip data string, which can be saved with e.g the Files extension.

The type can be one of the following:

The compression level decides how much the zip is compressed.
Lower compression levels will result in a bigger file, but are faster to create. Usually, high compression levels provide diminishing returns (lesser gains the higher you go) with much slower speeds.

A compression level of 0 (no compression) is the fastest, but will often result in a very big file.


remove current archive :: #a49a3a

Removes the current archive from the list of opened archives. Use this after you're done working with it.


<archive is open? :: #a49a3a>

Returns true if an archive is open.


<error opening archive? :: #a49a3a>

Returns true if the last "open archive" block used had an error (e.g if you provided an empty archive name or passed an invalid zip file).

Multi-archive blocks

Multiple archives can be open at a time, but there is one "current archive" that most blocks operate on. These blocks handle switching between and using multiple archives.


(current archive name :: #a49a3a)

Returns the name of the currently open archive (or an empty string if there isn't one).


(currently open archives :: #a49a3a)

Returns the list of currently open archives, as a JSON array (which you can parse with the JSON extension).


switch to archive named [other archive] :: #a49a3a

Switches the current archive to another one. If the given archive name does not exist. does nothing. If the given archive name is an empty string, switches to no currently open archive without removing any.


remove all archives :: #a49a3a

Removes all archives that are currently open.

File blocks

Blocks for working with files (and blocks that are general to both files and folders/directories.)


<folder [folder/] exists? :: #a49a3a>

Returns if a file or directory exists or not. The slash at the end matters! If a directory named folder exists, [folder] exists? will return false, but [folder/] exists? will return true.


write file [new file.txt] content [Hello, world?] type (text v) :: #a49a3a

Writes content to a file, creating the file if it doesn't exist and replacing its existing data if it does.

The type can be one of the following:


rename [hello.txt] to [hello renamed.txt] :: #a49a3a

Renames a file or directory to another name. If the target file already exists, it will be overwritten. The current directory will also be updated. This block can also be used to move files to a different directory.


copy [hello.txt] to [Copy of hello.txt] :: #a49a3a

Copies a file or directory elsewhere. If the target file already exists, it will be overwritten.


copy [hello.txt] in [archive] to [Copy of hello.txt] in [other archive] :: #a49a3a

Copies a file or directory between archives. If the target file already exists, it will be overwritten.


delete [hello.txt] :: #a49a3a

Deletes a file or directory (including everything in it).

If the current directory is in that directory, it will be set to the closest existing parent directory.


(file [hello.txt] as (text v) :: #a49a3a)

Get the contents of a file.

The type can be one of the following:

File info blocks

Blocks for getting and setting additional information on a file.


set (modified days since 2000 v) of [folder/dango.png] to [0] :: #a49a3a

Set additional info on a file or directory.

Available options:


((name v) of [folder/dango.png] :: #a49a3a)

Get additional info on a file or directory.

Available options:

Directory blocks

Blocks that deal with directories and the current directory.


create directory [new folder] :: #a49a3a

Creates a directory with a name. This can create multiple directories at once (by having multiple directores in the path, like /new folder1/new folder2/new folder3/).


go to directory [folder] :: #a49a3a

Moves the current directory (the default origin of most file operations) to the specified directory. If it doesn't exist, this block will do nothing. Use .. to go to the previous (parent) directory, and / to go to the root.


(contents of directory [.] :: #a49a3a)

Returns a list of files in a directory, as a JSON array (which you can parse with the JSON extension).


(current directory path :: #a49a3a)

Returns the absolute path to the current directory.

Other blocks

Miscellaneous stuff.


set archive comment to [any text] :: #a49a3a

Sets the archive's comment to some text. Just like file comments, this is saved and may be displayed as metadata by some programs.


(archive comment :: #a49a3a)

Returns the archive's comment.


(path [../folder3/] from [/folder/folder2] :: #a49a3a)

Returns an absolute path from an origin path and a target path. Does not depend on the archive, so it works without one open. This is mostly a utility used internally, but it might be useful for users too.