Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
neoppod
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Levin Zimmermann
neoppod
Commits
89583030
Commit
89583030
authored
Sep 12, 2017
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
339f3e1c
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
9 deletions
+42
-9
go/neo/t/zhash.go
go/neo/t/zhash.go
+28
-9
go/neo/t/zhash.py
go/neo/t/zhash.py
+14
-0
No files found.
go/neo/t/zhash.go
View file @
89583030
...
...
@@ -33,16 +33,32 @@ type hasher struct {
name
string
}
// hasher that discards data
type
nullHasher
struct
{}
func
(
h
nullHasher
)
Write
(
b
[]
byte
)
(
int
,
error
)
{
return
len
(
b
),
nil
}
func
(
h
nullHasher
)
Sum
(
b
[]
byte
)
[]
byte
{
return
[]
byte
{
0
}
}
func
(
h
nullHasher
)
Reset
()
{}
func
(
h
nullHasher
)
Size
()
int
{
return
1
}
func
(
h
nullHasher
)
BlockSize
()
int
{
return
1
}
func
main
()
{
defer
log
.
Flush
()
fadler32
:=
flag
.
Bool
(
"adler32"
,
false
,
"compute Adler32 checksum"
)
fnull
:=
flag
.
Bool
(
"null"
,
false
,
"don't compute hash - just read data"
)
fadler32
:=
flag
.
Bool
(
"adler32"
,
false
,
"compute Adler32 checksum"
)
fcrc32
:=
flag
.
Bool
(
"crc32"
,
false
,
"compute CRC32 checksum"
)
fsha1
:=
flag
.
Bool
(
"sha1"
,
false
,
"compute SHA1 cryptographic hash"
)
fsha256
:=
flag
.
Bool
(
"sha256"
,
false
,
"compute SHA256 cryptographic hash"
)
fsha512
:=
flag
.
Bool
(
"sha512"
,
false
,
"compute SHA512 cryptographic hash"
)
useprefetch
:=
flag
.
Bool
(
"useprefetch"
,
false
,
"prefetch loaded objects"
)
flag
.
Parse
()
url
:=
flag
.
Args
()[
0
]
// XXX dirty
if
flag
.
NArg
()
!=
1
{
flag
.
Usage
()
// XXX exit
}
url
:=
flag
.
Arg
(
0
)
ctx
:=
context
.
Background
()
...
...
@@ -57,6 +73,7 @@ func main() {
}
switch
{
case
*
fnull
:
inith
(
"null"
,
func
()
hash
.
Hash
{
return
nullHasher
{}
})
case
*
fadler32
:
inith
(
"adler32"
,
func
()
hash
.
Hash
{
return
adler32
.
New
()
})
case
*
fcrc32
:
inith
(
"crc32"
,
func
()
hash
.
Hash
{
return
crc32
.
NewIEEE
()
})
case
*
fsha1
:
inith
(
"sha1"
,
sha1
.
New
)
...
...
@@ -99,7 +116,7 @@ func zhash(ctx context.Context, url string, h hasher, useprefetch bool) (err err
}
}
load
:=
func
(
ctx
context
.
Context
,
xid
zodb
.
Xid
)
(
[]
byte
,
zodb
.
Tid
,
error
)
{
load
:=
func
(
ctx
context
.
Context
,
xid
zodb
.
Xid
)
(
*
zodb
.
Buf
,
zodb
.
Tid
,
error
)
{
if
cache
!=
nil
{
return
cache
.
Load
(
ctx
,
xid
)
}
else
{
...
...
@@ -158,7 +175,7 @@ loop:
if
xid
.
Oid
%
8
==
0
{
prefetchBlk
(
ctx
,
xid
)
}
data
,
_
,
err
:=
load
(
ctx
,
xid
)
buf
,
_
,
err
:=
load
(
ctx
,
xid
)
switch
err
.
(
type
)
{
case
nil
:
// ok
...
...
@@ -168,13 +185,15 @@ loop:
return
err
}
h
.
Write
(
d
ata
)
h
.
Write
(
buf
.
D
ata
)
//fmt.Fprintf(os.Stderr, "%d @%s\tsha1: %x\n", uint(oid), serial, h.Sum(nil))
//fmt.Fprintf(os.Stderr, "\tdata: %x\n",
d
ata)
//fmt.Fprintf(os.Stderr, "\tdata: %x\n",
buf.D
ata)
nread
+=
len
(
d
ata
)
nread
+=
len
(
buf
.
D
ata
)
oid
+=
1
buf
.
Free
()
}
tend
:=
time
.
Now
()
...
...
go/neo/t/zhash.py
View file @
89583030
...
...
@@ -14,6 +14,16 @@ import sys
from
time
import
time
from
getopt
import
getopt
,
GetoptError
# hasher that discards data
class
NullHasher
:
name
=
"null"
def
update
(
self
,
data
):
pass
def
hexdigest
(
self
):
return
"00"
# adler32 in hashlib interface
class
Adler32Hasher
:
name
=
"adler32"
...
...
@@ -42,6 +52,7 @@ class CRC32Hasher:
# {} name -> hasher
hashRegistry
=
{
"null"
:
NullHasher
,
"adler32"
:
Adler32Hasher
,
"crc32"
:
CRC32Hasher
,
"sha1"
:
hashlib
.
sha1
,
...
...
@@ -55,6 +66,7 @@ def usage(w):
options:
--null don't compute hash - just read data
--adler32 compute Adler32 checksum
--crc32 compute CRC32 checksum
--sha1 compute SHA1 cryptographic hash
...
...
@@ -72,6 +84,7 @@ def main():
for
opt
,
_
in
optv
:
if
opt
in
(
"-h"
,
"--help"
):
print
(
__doc__
)
usage
(
sys
.
stdout
)
sys
.
exit
()
...
...
@@ -80,6 +93,7 @@ def main():
h
=
hctor
()
if
len
(
argv
)
!=
1
:
print
(
__doc__
)
usage
(
sys
.
stderr
)
sys
.
exit
(
1
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment