From bc5807b20afa0af4a3329ce389513785b097421f Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Wed, 30 Sep 2009 02:26:32 -0500 Subject: [PATCH] add examples to checksums docs --- core/checksums/checksums-docs.factor | 30 +++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/core/checksums/checksums-docs.factor b/core/checksums/checksums-docs.factor index a05bf3a685..4ffd6f4427 100644 --- a/core/checksums/checksums-docs.factor +++ b/core/checksums/checksums-docs.factor @@ -20,15 +20,39 @@ HELP: checksum-stream HELP: checksum-bytes { $values { "bytes" "a sequence of bytes" } { "checksum" "a checksum specifier" } { "value" byte-array } } -{ $contract "Computes the checksum of all data in a sequence." } ; +{ $contract "Computes the checksum of all data in a sequence." } +{ $examples + { $example + "USING: checksums checksums.crc32 prettyprint ;" + "B{ 1 10 100 } crc32 checksum-bytes ." + "B{ 78 179 254 238 }" + } +} ; HELP: checksum-lines { $values { "lines" "a sequence of sequences of bytes" } { "checksum" "a checksum specifier" } { "value" byte-array } } -{ $contract "Computes the checksum of all data in a sequence." } ; +{ $contract "Computes the checksum of all data in a sequence." } +{ $examples + { $example + "USING: checksums checksums.crc32 prettyprint ;" +"""{ + "Take me out to the ball game" + "Take me out with the crowd" +} crc32 checksum-lines .""" + "B{ 111 205 9 27 }" + } +} ; HELP: checksum-file { $values { "path" "a pathname specifier" } { "checksum" "a checksum specifier" } { "value" byte-array } } -{ $contract "Computes the checksum of all data in a file." } ; +{ $contract "Computes the checksum of all data in a file." } +{ $examples + { $example + "USING: checksums checksums.crc32 prettyprint ;" + """"resource:license.txt" crc32 checksum-file .""" + "B{ 100 139 199 92 }" + } +} ; ARTICLE: "checksums" "Checksums" "A " { $emphasis "checksum" } " is a function mapping sequences of bytes to fixed-length strings. While checksums are not one-to-one, a good checksum should have a low probability of collision. Additionally, some checksum algorithms are designed to be hard to reverse, in the sense that finding an input string which hashes to a given checksum string requires a brute-force search."