shithub: tarsum

Download patch

ref: 8e87dfb15e3d9f3c940b3de2378c0591e2e97a12
parent: 01c1c0c7779125f8a83f75ecb277f0d63ead9200
author: B. Atticus Grobe <[email protected]>
date: Thu Feb 24 07:18:43 EST 2022

style changes

--- a/tarsum.fnl
+++ b/tarsum.fnl
@@ -10,15 +10,16 @@
 ;; (local tarball (io.open (. arg 1) "r+b"))
 
 (with-open (tarball (io.open (. arg 1) "r+b"))
-(let [header (tarball:read 0x132) headertbl {}]
+(let [header (tarball:read 0x132)]
   (if (= header fail) (error "Unable to read file."))
   (if (~= (# header) 0x132) (error "Invalid header! (Is this really a tarball?)"))
-  (for [i 1 (# header) 1] (table.insert headertbl (string.sub header i i)))
+  (var headertbl {})
+  (for [i 1 (# header) 1] (table.insert headertbl (header:sub i i)))
   (for [i 0x94 0x9b 1] (tset headertbl i " "))
   (var header "")
   (each [k v (ipairs headertbl)] (set header (.. header v)))
   (var sum 0)
-  (for [i 1 (# header) 1] (set sum (+ sum (string.byte header i))))
+  (for [i 1 (# header) 1] (set sum (+ sum (header:byte i))))
   (print (string.format "Checksum: %.7o\n" sum))
   (if (~= (tarball:seek "set" 0x94) 0x94) (error "Could not seek to 0x94"))
   (tarball:write (string.format "%.7o" sum))