(Formerly called "Package")
This script is basically a modified version of the fabled "pastebin" script - it can send or receive files to or from your computer.
However, it has a couple of differences. First off, it supports multiple files per paste - tell it to upload a directory, and it'll do just that. The whole lot can then be downloaded elsewhere with one command. Whole system backups made easy!
On top of compressing with LZW, it also translates the upload into something ASCII-compatible, meaning that ComputerCraft won't strip out certain symbols as it would if you were using the regular pastebin script. Although this means the results aren't easily human-readable, it allows transmission of data that would otherwise be difficult to obtain when playing on an online MineCraft server (such as NBS files for Note, or schematic files for this schematic builder).
Note that bbpack's uploads will usually trigger pastebin's spam filtering system. You'll hence likely need to look up your paste in a web browser and fill in a captcha to complete the uploading process.
As of v1.6.0, BBPack implements a file system wrapper when loaded. By default this only adds a RAM drive (accessible via the root of your drive as "ram"), though it can also be configured to compress all of your files transparently, mount online files as if they were on your local drive, and connect to "clusters" - other ComputerCraft systems acting as combined storage drives.
It can either be executed as a regular script, or loaded as an API:
Script Usage
Uploads specified file or directory:bbpack put [file / directory name]
Dumps paste into specified file or directory:
bbpack get <pasteid> [file / directory name]
Saves to a file, instead of uploading:
bbpack fileput [file / directory name] <archive>
Reads from a file, instead of downloading:
bbpack fileget <archive> [file / directory name]
If the [file / directory name] to pack / unpack to is excluded, it'll use the system root instead (eg, "bbpack put" uploads everything).
Mounts the specified web URL as a local file (or directory, if the URL is for a GitHub repo), or the specified cluster as a local directory:
bbpack mount (<URL> <localPath>) / (<cluster>)
Compresses your HDD (will also automatically compress files added in the future):
bbpack compress
Decompresses your HDD (or as much as it can before running out of space):
bbpack decompress
Turns the system into a server for the specified cluster:
bbpack cluster <cluster>
Updates bbpack on the current system and reboots, also instructing all mounted cluster server servers to do the same:
bbpack update
API Usage
bbpack.toBase64(table byte-values) => string textConverts a given table of byte-values into a base64-based string (note: length will be increased by a third, eg three bytes becomes a four-character string).
bbpack.fromBase64(string text) => table byte-values
Converts a given base64-based string into a table of byte-values (eg a four character string becomes three bytes).
bbpack.compress(table byte-values / string text [, number value range]) => table byte-values
Applies LZW compression to a given table of byte-values or to a string. The value range must be a power of two that is higher than the largest byte value that may be in your input stream; the lower this is, the smaller the archive will be. Defaults to 256, though 128 is suitable for text.
bbpack.decompress(table byte-values [, boolean outputText [, number value range]]) => table byte-values / string text
Decompresses a given table of LZW-compressed byte-values. Type of the returned result depends on whether outputText is defined as true. The value range must match whatever the content was compressed with, defaulting to 256 if unspecified.
bbpack.uploadPaste(string name, string content) => string pasteID
Uploads a given string to pastebin.com (as a guest, no expiry), then returns the new paste ID.
bbpack.downloadPaste(string pasteID) => string content
Downloads and returns the content of a given pastebin.com paste.
bbpack.open(string file name, string file mode [, number value range]) => table file handle
Returns a file handle similar to that produced by fs.open() (usage is the same), but linked to bbpack's compression system. These handles include an additional function, file.extractHandle(), which returns a copy of the actual file handle being used.
bbpack.lines(string file name) => function iterator
It's io.lines(), but rigged to work with text-mode files created with bbpack.open().
Note: Each of the above functions (except downloadPaste) alternatively accepts file handles produced by fs.open(). If used, they'll automatically read out the contents and then close the handle. Be sure to specify mode "r" for text, or "rb" for binary (byte-values). Also note that bbpack.open() requires binary-mode handles, and bbpack.lines() requires text-mode bbpack.open() handles.
bbpack.fileSys()
Controls BBPack's filesystem wrapper. Accepts various parameters:
bool true/false: Compresses or decompresses the filesystem.
string cluster: Mounts the specified cluster as a local directory.
string url, string path: Mounts the specified web URL as a local file, or if the path is to a GitHub repo, as a directory.
bbpack.update()
Updates BBPack and reboots. Also instructs all mounted cluster servers to do the same.
File names are included in each paste for all files, so if you eg upload a single file, it's up to you whether you download it under a new name (by specifying one with the "get" command) or not (by using the "get" command on its own).
For example, if you wanted to download this pre-packed set of NBS files (as included with Note Block Studio), you'd enter:
bbpack get CYRmLz78 Songs
Version History
2015/01/291.0.0
Initial release.
2015/02/03
1.1.0
Can now be loaded as an API.
2015/04/17
1.2.0
Script:
Now records empty directories.
No longer includes external disk drives when performing uploads of root.
Added fileput / fileget parameters (for saving to / loading from the computer's own drive, as opposed to pastebin).
API:
Added bbpack.open().
Added bbpack.lines().
2015/04/19
1.2.1
bbpack.open() now accepts an optional third parameter, "value range", same as compress / decompress.
2015/12/11
1.3.0
Because I'm an idiot, base64 implementation was non-standard. This build corrects it and hence breaks compatibility with all base64 strings produced using older bbpack builds.
2015/12/21
1.3.1
Updated for new pastebin RAW access path.
2017/06/06
1.5.0
Compression ~20% faster, decompression ~100% faster.
Updated bbpack.open() to match new fs.open() behaviours (binary mode: includes readAll (returns string), read supports numeric argument (returns string if used), write accepts strings).
Renamed from "package" to "bbpack" due to alternate "package" API's inclusion into mainline ComputerCraft releases.
2017/07/28
1.6.0
BBPack now installs an FS wrapper when loaded, providing a RAM drive, web mounts, distributed filesystems, and a compressed filesystem. Controllable via bbpack.fileSys().
Also added bbpack.update().
2017/09/07
1.6.1
Can now mount GitHub repos.