shaproxy

package module
v0.0.0-...-96b4a94 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2017 License: GPL-3.0 Imports: 4 Imported by: 2

README

This code can do inline sha256 calculations godoc:

package main

import (
    "github.com/Harnish/sha256proxy"
    "fmt"
    "io"
    "os"
)

func main() {
    shain := shaproxy.New()
   
    f, err := os.Open("myfile.txt")
    if err != nil {
        fmt.Println(err)
    }

    fo, err := os.Create("junk.file")
    if err != nil {
        fmt.Println(err)
    }

    reader := shain.NewProxyReader(f)
    io.Copy(fo, reader)
    shain.Finish()
    fmt.Println(shain.SumHex())

}

I used gopkg.in/cheggaaa/pb.v1 as the example for this as I was trying to add progress to my app that sha256s the file before and after the transaction.

Documentation

Overview

Package shaproxy provides a stream reader object to allow calculating mulitple sha256s inline. This is useful when capturing the sha256 prior to transformation of data and after.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Reader

type Reader struct {
	io.Reader
	// contains filtered or unexported fields
}

Impliments a proxy reader.

func (*Reader) Close

func (r *Reader) Close() (err error)

func (*Reader) Read

func (r *Reader) Read(p []byte) (n int, err error)

type ShaProxy

type ShaProxy struct {
	// ShaHash is the Hash object that is added to as the stream is read
	ShaHash hash.Hash
	// contains filtered or unexported fields
}

func New

func New() *ShaProxy

New creates and returns a shaproxy object.

func (*ShaProxy) Finish

func (me *ShaProxy) Finish()

This executes the final calculation of the sha256 sum and sets the values.

func (*ShaProxy) NewProxyReader

func (me *ShaProxy) NewProxyReader(r io.Reader) *Reader

This takes an io.Reader and returns an io.Reader. It does not modify the data in the stream but adds to the object's hash.

func (*ShaProxy) SumBytes

func (me *ShaProxy) SumBytes() []byte

Returns the value from the private sumBytes variable in a byteslice representation. Requires Finish to be called before the value is populated.

func (*ShaProxy) SumHex

func (me *ShaProxy) SumHex() string

Retruns the private variable sumHex, which is the hex representation in a string. Requires Finish to be called before the value is populated.

Jump to

Keyboard shortcuts

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