PP
Size: a a a
PP
KR
Г
ST
loop
read n
calc hash
accumulate
PP
ST
Г
ST
PP
ST
(defn read-bytes
[filename, n-bytes]
(let [file (io/file filename)
cbuf (char-array n-bytes)
cbuf2 (char-array n-bytes)]
(with-open [r (io/reader file)]
(.read r cbuf)
(.read r cbuf2)
[(seq cbuf)
(seq cbuf2)])))
=> #'dev.playground/read-bytes
(read-bytes "package.json" 10)
=> [(\{ \newline \space \space \" \n \a \m \e \") (\: \space \" \l \u \c \k \y \- \w)]
ST
read
возвращает The number of characters read, or -1 if the end of the stream has been reachedГ
ST
ST
Г
ST
(defn calc-file-hash
[filename, n-bytes]
(let [file (io/file filename)
buf (byte-array n-bytes)
md (MessageDigest/getInstance "MD5")]
(with-open [r (io/input-stream file)]
(loop [acc []]
(if (pos? (.read r buf))
(recur (conj acc (.digest md)))
acc)))))
=> #'dev.playground/calc-file-hash
(calc-file-hash "package.json" 100)
=>
[#object["[B" 0x284ee57 "[B@284ee57"]
#object["[B" 0x1e2c5a65 "[B@1e2c5a65"]
#object["[B" 0xa5b8f09 "[B@a5b8f09"]
#object["[B" 0x26851364 "[B@26851364"]
#object["[B" 0x3d6b7b5 "[B@3d6b7b5"]
#object["[B" 0x7fd52ad8 "[B@7fd52ad8"]]
ST
(defn calc-file-hash
[filename, n-bytes]
(let [file (io/file filename)
buf (byte-array n-bytes)
md (MessageDigest/getInstance "MD5")]
(with-open [r (io/input-stream file)]
(loop [acc []]
(if (pos? (.read r buf))
(recur (conj acc (.digest md)))
acc)))))
=> #'dev.playground/calc-file-hash
(calc-file-hash "package.json" 100)
=>
[#object["[B" 0x284ee57 "[B@284ee57"]
#object["[B" 0x1e2c5a65 "[B@1e2c5a65"]
#object["[B" 0xa5b8f09 "[B@a5b8f09"]
#object["[B" 0x26851364 "[B@26851364"]
#object["[B" 0x3d6b7b5 "[B@3d6b7b5"]
#object["[B" 0x7fd52ad8 "[B@7fd52ad8"]]
Г
ST