memdigest

package module
v0.0.0-...-534e0f5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 16, 2019 License: MIT Imports: 7 Imported by: 0

README

go-memdigest

Package memdigest provides an in memory content-addressable storage (CAS), and can be used as a CAS for the digestfs content-addressable virtual file system (VFS).

Documention

Online documentation, which includes examples, can be found at: http://godoc.org/github.com/reiver/go-memdigest

GoDoc

Example

Here is an example of how to use memdigest via digestfs

import (
	"github.com/reiver/go-digestfs"
	"github.com/reiver/go-memdigest"
)

// ...

var mem memdigest.SHA1

// ...

var mountpoint digestfs.MountPoint

err := mountpoint.Mount("memdigest.SHA1", &mem)

// ...

// algorithm == "SHA-1"
// digest    == "\x70\xcc\x03\xf6\x11\xf4\x57\x34\x2c\x7b\xf6\x9e\x7b\xd3\xca\x0e\xab\xf1\x7d\x75" // 0x70cc03f611f457342c7bf69e7bd3ca0eabf17d75
algorithm, digest, err := mountpoint.Create([]byte("The request has been accepted for processing, but the processing has not been completed."))

// ...

// algorithm == "SHA-1"
// digest    == "\xf5\x88\x02\xbc\x6a\xdb\xe9\x02\x81\x75\x96\x82\xfb\xcf\xed\x60\x45\xb0\x3a\x26" // 0xf58802bc6adbe90281759682fbcfed6045b03a26
algorithm, digest, err := mountpoint.Create([]byte("The server has fulfilled the request but does not need to return an entity-body, and might want to return updated metainformation."))

// ...

// algorithm == "SHA-1"
// digest    == "\x59\xd4\xcf\x28\xc9\x83\x1a\xde\x81\x2e\x9b\xa3\x91\x90\x40\xba\xed\xea\x92\x66" // 0x59d4cf28c9831ade812e9ba3919040baedea9266
algorithm, digest, err := mountpoint.Create([]byte("The server encountered an unexpected condition which prevented it from fulfilling the request."))

// ...

content, err := mountpoint.Open("SHA-1", "\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") // 0xc0535e4be2b79ffd93291305436bf889314e4a3faec05ecffcbb7df31ad9e51a
if nil != err {
	return err
}
defer content.Close()

See Also

Documentation

Overview

Package memdigest provides an in memory content-addressable storage (CAS), and can be used as a CAS for the digestfs (https://github.com/reiver/go-digestfs) content-addressable virtual file system (VFS).

Example

Package memdigest can be used via digestfs. For example:

import (
	"github.com/reiver/go-digestfs"
	"github.com/reiver/go-memdigest"
)

// ...

var mem memdigest.SHA1

// ...

var mountpoint digestfs.MountPoint

err := mountpoint.Mount("memdigest.SHA1", &mem)

// ...

// algorithm == "SHA-1"
// digest    == "\x70\xcc\x03\xf6\x11\xf4\x57\x34\x2c\x7b\xf6\x9e\x7b\xd3\xca\x0e\xab\xf1\x7d\x75" // 0x70cc03f611f457342c7bf69e7bd3ca0eabf17d75
algorithm, digest, err := mountpoint.Create([]byte("The request has been accepted for processing, but the processing has not been completed."))

// ...

// algorithm == "SHA-1"
// digest    == "\xf5\x88\x02\xbc\x6a\xdb\xe9\x02\x81\x75\x96\x82\xfb\xcf\xed\x60\x45\xb0\x3a\x26" // 0xf58802bc6adbe90281759682fbcfed6045b03a26
algorithm, digest, err := mountpoint.Create([]byte("The server has fulfilled the request but does not need to return an entity-body, and might want to return updated metainformation."))

// ...

// algorithm == "SHA-1"
// digest    == "\x59\xd4\xcf\x28\xc9\x83\x1a\xde\x81\x2e\x9b\xa3\x91\x90\x40\xba\xed\xea\x92\x66" // 0x59d4cf28c9831ade812e9ba3919040baedea9266
algorithm, digest, err := mountpoint.Create([]byte("The server encountered an unexpected condition which prevented it from fulfilling the request."))

// ...

content, err := mountpoint.Open("SHA-1", "\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") // 0xc0535e4be2b79ffd93291305436bf889314e4a3faec05ecffcbb7df31ad9e51a
if nil != err {
	return err
}
defer content.Close()

The reason why one would use memdigest through digestfs, rather than use memdigest directly, is because so that memdigest could be swapped out with another content-addressable storage (CAS), or combined with another content-addressable storage (CAS), and code using digestfs would (almost completely) remain the same.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type SHA1

type SHA1 struct {
	// contains filtered or unexported fields
}

func (*SHA1) Create

func (receiver *SHA1) Create(p []byte) (algorithm string, digest string, err error)

Create makes *memdigest.SHA1 fit the digestfs_driver.MountPoint interface.

Create is very similar to Store, in that it tores ‘content’ and returns the SHA-1 digest of ‘content’.

Example

Here is an example of it being used:

var mem *memdigest.SHA1

// ...

var content []byte = []byte("The request has been fulfilled and resulted in a new resource being created.")

// ...

algorithm, digest, err := mem.Create(content)

The returned digest is in binary form, not hexadecimal.

In the case of our example, it will be:

[64]byte{0x0c, 0xe9, 0xff, 0x3b, 0x12, 0xaf, 0xdb, 0x31, 0x61, 0x75, 0x1e, 0x3a, 0xb4, 0x49, 0x87, 0x62, 0x95, 0x23, 0x63, 0x3d}

If you want to convert it to hexadecimal, you can do so with code such as:

hexadecimalDigest := fmt.Sprintf("%x", digest)

Which will return the string:

"0ce9ff3b12afdb3161751e3ab44987629523633d"

More typically though, this would be use Create through package digestfs.

func (*SHA1) Load

func (receiver *SHA1) Load(digest []byte) (string, bool)

func (*SHA1) Open

func (receiver *SHA1) Open(algorithm string, digest string) (digestfs_driver.Content, error)

func (*SHA1) OpenLocation

func (receiver *SHA1) OpenLocation(location string) (digestfs_driver.Content, error)

OpenLocation makes *memdigest.SHA1 fit the digestfs_driver.MountPoint interface.

func (*SHA1) Store

func (receiver *SHA1) Store(content []byte) ([sha1.Size]byte, error)

Store stores ‘content’ and returns the SHA-1 digest of ‘content’.

Example

Here is an example of it being used:

var mem *memdigest.SHA1

// ...

var content []byte = []byte("The request has been fulfilled and resulted in a new resource being created.")

// ...

digest, err := mem.Store(content)

The returned digest is in binary form, not hexadecimal.

In the case of our example, it will be:

[64]byte{0x0c, 0xe9, 0xff, 0x3b, 0x12, 0xaf, 0xdb, 0x31, 0x61, 0x75, 0x1e, 0x3a, 0xb4, 0x49, 0x87, 0x62, 0x95, 0x23, 0x63, 0x3d}

If you want to convert it to hexadecimal, you can do so with code such as:

hexadecimalDigest := fmt.Sprintf("%x", digest)

Which will return the string:

"0ce9ff3b12afdb3161751e3ab44987629523633d"

func (*SHA1) Unmount

func (receiver *SHA1) Unmount() error

Unmount makes *memdigest.SHA1 fit the digestfs_driver.MountPoint interface.

Unmount will never return an error, but will (conceptually) remove all content it was previously storing.

Example

Here is an example of it being used:

var mem *memdigest.SHA1

// ...

err := mem.Unmount()

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL