mirror of
https://github.com/vbatts/go-mtree.git
synced 2025-07-13 18:29:11 +00:00
*: loads of walking features
For the most part, all the keywords for a standard mtree spec now have a function to produce the contents for a creator. These are used in the "walk" function, and will be used next in the "check" logic. This is still a WIP, as the DirectoryHierarchy produced from the current Walk() is not all-together a valid document. Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
This commit is contained in:
parent
7842a80f95
commit
455edf6d21
8 changed files with 332 additions and 0 deletions
48
cksum.go
Normal file
48
cksum.go
Normal file
|
@ -0,0 +1,48 @@
|
|||
package mtree
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"io"
|
||||
)
|
||||
|
||||
const posixPolynomial uint32 = 0x04C11DB7
|
||||
|
||||
func cksum(r io.Reader) (uint32, int, error) {
|
||||
in := bufio.NewReader(r)
|
||||
count := 0
|
||||
var sum uint32 = 0
|
||||
f := func(b byte) {
|
||||
for i := 7; i >= 0; i-- {
|
||||
msb := sum & (1 << 31)
|
||||
sum = sum << 1
|
||||
if msb != 0 {
|
||||
sum = sum ^ posixPolynomial
|
||||
}
|
||||
}
|
||||
sum ^= uint32(b)
|
||||
}
|
||||
|
||||
for done := false; !done; {
|
||||
switch b, err := in.ReadByte(); err {
|
||||
case io.EOF:
|
||||
done = true
|
||||
case nil:
|
||||
f(b)
|
||||
count++
|
||||
default:
|
||||
return ^sum, count, err
|
||||
}
|
||||
}
|
||||
for m := count; ; {
|
||||
f(byte(m) & 0xff)
|
||||
m = m >> 8
|
||||
if m == 0 {
|
||||
break
|
||||
}
|
||||
}
|
||||
f(0)
|
||||
f(0)
|
||||
f(0)
|
||||
f(0)
|
||||
return ^sum, count, nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue