cksum(n)
π cksum(n) β Cyclic Redundancy Checks π
okay bestie, pull up a chair, we're doing checksums today and honestly? it's giving iconic.
This is the cksum(n) manual page from tcllib, version 1.1.5. Yes, the (n) means it lives in the Tcl manual section, and yes, we're gonna read the whole thing together. π«Ά
β¨ NAME β¨
cksum β Calculate a cksum(1) compatible checksum
Like, it makes the same kind of checksum the Unix cksum(1) tool makes. That's it, that's the vibe. π
β¨ SYNOPSIS β¨
package require Tcl 8.5 9
package require cksum ?1.1.5?
::crc::cksum ?-format format? ?-chunksize size? [ -channel chan |
-filename file | string ]
::crc::CksumInit
::crc::CksumUpdate token data
::crc::CksumFinal token
the ?question marks? mean "optional, bestie", and the |pipes| mean "pick one, not all of them".
β¨ DESCRIPTION β¨
So this package gives you a Tcl implementation of the cksum(1) algorithm, and it's based on info provided at in the GNU implementation of this program, as part of the GNU Textutils 2.0 package. No cap. π
β¨ COMMANDS β¨
πΈ ::crc::cksum ?-format format? ?-chunksize size? [ -channel chan | -filename file | string ]
This one takes string data, or a channel, or a file name β your choice, main character energy β¨ β and returns a checksum value calculated with the cksum(1) algorithm.
The result gets formatted using the format(n) specifier you hand it, or, if you don't say anything, it's an unsigned integer (%u) by default. π
β¨ OPTIONS β¨
-channelname β Returns a checksum for the data read from a channel. The command will read data from the channel until theeofis true. But heads up: if you need to be able to process events during this calculation, go look at the PROGRAMMING INTERFACE section instead. π-filenamename β This is the convenience option, bestie π. It opens the specified file, sets the encoding tobinary, and then acts exactly as if the-channeloption had been used. The file is closed on completion. One and done, slay.-formatstring β Return the checksum using an alternative format template. That's the whole thing. Customise your lil output. β¨
β¨ PROGRAMMING INTERFACE β¨
Okay so this is the part where it gets fun π
β the cksum package implements the checksum using a context variable, and you can add more data to it at any time. Lowkey perfect for an event-based environment like a Tk application or a web server package.
Data to be checksummed may be handled incrementally, during a fileevent handler, in discrete chunks. This can improve the interactive nature of a GUI application and can help to avoid excessive memory consumption. So it's not just cute, it's efficient. π₯
π¦ ::crc::CksumInit
Begins a new cksum context. Returns a token ID that you must use for the remaining functions. An optional seed may be specified if required. π±
π¦ ::crc::CksumUpdate token data
Add data to the checksum identified by token. Calling CksumUpdate $token "abcd" is equivalent to calling CksumUpdate $token "ab" followed by CksumUpdate $token "cb". Wild, right?? See the EXAMPLES section for the receipts. π
π¦ ::crc::CksumFinal token
Returns the checksum value and releases any resources held by this token. Once this command completes, the token will be invalid β it's gone, it's over, no takebacks π. The result is a 32 bit integer value.
β¨ EXAMPLES β¨
Look at her go π:
% crc::cksum "Hello, World!"
2609532967
% crc::cksum -format 0x%X "Hello, World!"
0x9B8A5027
% crc::cksum -file cksum.tcl
1828321145
% set tok [crc::CksumInit]
% crc::CksumUpdate $tok "Hello, "
% crc::CksumUpdate $tok "World!"
% crc::CksumFinal $tok
2609532967
not the incremental one landing on the exact same 2609532967 as the one-shot version π consistency ate and left no crumbs.
β¨ AUTHORS β¨
Pat Thoyts β thank you for your service, king ππ
β¨ BUGS, IDEAS, FEEDBACK β¨
So, this document and the package it describes will undoubtedly contain bugs and other problems. Like, obviously. π
Please report such in the category crc of the Tcllib Trackers at http://core.tcl.tk/tcllib/reportlist. Please also report any ideas for enhancements you may have for either the package and/or the documentation β we wanna hear it, fr fr. π
When proposing code changes, please provide unified diffs, i.e. the output of diff -u.
Note further that attachments are strongly preferred over inlined patches. Attachments can be made by going to the Edit form of the ticket immediately after its creation, and then using the left-most button in the secondary navigation bar. β¨
β¨ SEE ALSO β¨
go read those too bestie, they're in the family πΈ
β¨ KEYWORDS β¨
checksum, cksum, crc, crc32, cyclic redundancy check, data integrity, security
β¨ CATEGORY β¨
Hashes, checksums, and encryption πβ¨
β¨ COPYRIGHT β¨
Copyright (c) 2002, Pat Thoyts
and that's the whole page, bestie!! you now know cksum better than most people ever will. vibe check: passed β
π¦
this lil gem came from tcllib, version 1.1.5, dated with the cksum(n) manual page name β go forth and checksum responsibly, mwah π
π
π¦ where this page comes from
- fedora 43: tcllib 2.0-3.fc43 Β· TCL
- fedora 44: tcllib 2.0-4.fc44 Β· TCL
- nixos 26.05: tcllib 2.0
- nixpkgs unstable: tcllib 2.0
- Copyright (c) 2002, Pat Thoyts
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms