Log In  

Cart #util_crc32-0 | 2024-03-21 | Embed ▽ | License: CC4-BY-NC-SA
2

This cartridge is an installer and uninstaller for a new globally-available command: 'crc32'.

Installation

Install with yotta:

  • yotta util install #util_crc32

Install without yotta:

  • load #util_crc32 in your Picotron terminal
  • Ctrl+R to run installer cartridge
  • Press X to install/uninstall as prompted
    (You can also manually copy the relevant files from the loaded cartridge from /ram/cart/exports to your system if you'd prefer.)

Description

This command will generate CRC32 checksums for the input parameter you provide, which can be either a file path, a folder path, or a bare text string.

If you give it a file, you'll get the file's checksum back.
If you give it a folder, it will checksum every file within the folder then checksum that output one more time to get you a single value.
If you give it neither a file nor a folder, you'll get the input string's checksum back. Note that you are not expected to quote-encapsulate the input string.

Use as a library

This utility file can be included in code as a library to expose the crc32() function:

crc32(input: string|path, is_file: boolean|nil = nil): string

This function will return just a checksum number alone. It will attempt to autodetect if it's a file if you omit is_file, based on file presence or lack thereof.

Checksum file operations

This command accepts three arguments that allow it to place a checksum it generates into a checksum list file (.crcs). You can either append the checksum to the target file, delete the checksum from the target file, or replace all checksums in the file with the newly generated one.

Append: > crc32 -a file.txt.crcs file.txt
Delete: > crc32 -d file.txt.crcs file.txt
Replace: > crc32 -r file.txt.crcs file.txt

Recursive checksumming with -V

This command has a -V or --version parameter.
This will take the provided target, a folder, and walk through every file within it to generate a checksum and place it into a [filename].crcs file alongside it. By default, it will append the hash to the crcs file. If you specify -d or -r, it will either delete or replace the crcs files appropriately.

Example:

> crc32 -V /ram/cart/exports
12345 /ram/cart/exports/subdir/file.txt
54321 /ram/cart/exports/subdir/another/manual.txt
> ?fetch("/ram/cart/exports/subdir/file.txt.crcs")
12345

This has plenty of uses I'm sure, but I use this for the new yotta version which supports providing .crcs files next to installable files within a package intended for system install. These .crcs files can be used to determine "safe" versions of the file that can be considered as owned by the package. This helps yotta avoid overwriting customized or external files that also might belong to a package, and helps my package installer/uninstaller shim not delete files that aren't owned by it.

P#144084 2024-03-21 22:04


[Please log in to post a comment]