-
Notifications
You must be signed in to change notification settings - Fork 1
/
doc.go
62 lines (37 loc) · 1.84 KB
/
doc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
Package digestfs provides a content-addressable virtual file system (VFS)
by providing a common interface to one or more content-addressable storage (CAS).
Example Opening
Here is an example of how to use an already mounted digestfs.MountPoint to get content:
content, err := mountpoint.Open("SHA-256", "\xc0\x53\x5e\x4b\xe2\xb7\x9f\xfd\x93\x29\x13\x05\x43\x6b\xf8\x89\x31\x4e\x4a\x3f\xae\xc0\x5e\xcf\xfc\xbb\x7d\xf3\x1a\xd9\xe5\x1a")
if nil != err {
return err
}
defer content.Close()
Note that if you had the digest encoded as hexadecimal, then you could decode it into binary using:
As in:
var hexadecimalDigest = "c0535e4be2b79ffd93291305436bf889314e4a3faec05ecffcbb7df31ad9e51a"
digestBytes, err := hex.DecodeString(hexadecimalDigest)
var digest string = string(digestBytes)
// digest == "\xc0\x53\x5e\x4b\xe2\xb7\x9f\xfd\x93\x29\x13\x05\x43\x6b\xf8\x89\x31\x4e\x4a\x3f\xae\xc0\x5e\xcf\xfc\xbb\x7d\xf3\x1a\xd9\xe5\x1a"
Here, ‘content’ would give you access to the data on the content mostly via an io.ReaderAt interface.
For example:
var buffer [256]byte
var p []byte = buffer[:]
var offset int64 = 0
n, err := content.ReadAt(p, offset)
Alternatively, if you want to use the io.Reader interface, you can upgrade ‘content’ from an io.ReaderAt to an io.Reader by using an io.SectionReader.
For example:
r := io.NewSectionReader(content, 0, int64(content.Len()))
// ...
contentBytes, err := ioutil.ReadAll(r)
Example Mounting
How you create a digestfs.MountPoint depends on which MountPoint you use.
But mounting looks something like:
var mountpoint digestfs.MountPoint
err := mountpoint.Mount("git", "/home/joeblow/workspaces/myproject")
Content-Addressable Storages
Some content-addressable storages (CAS) that can be used with digestfs include:
• https://godoc.org/github.com/reiver/go-memdigest
*/
package digestfs