MCPcopy Index your code
hub / github.com/boyter/hashit / processReadFileParallel

Function processReadFileParallel

processor/workers.go:647–820  ·  view source on GitHub ↗

For files under a certain size its faster to just read them into memory in one chunk and then process them which this method does NB there is little point in multi-processing at this level, it would be better done on the input channel if required

(filename string, content *[]byte)

Source from the content-addressed store, hash-verified

645// NB there is little point in multi-processing at this level, it would be
646// better done on the input channel if required
647func processReadFileParallel(filename string, content *[]byte) (Result, error) {
648 startTime := makeTimestampNano()
649
650 var wg sync.WaitGroup
651 result := Result{}
652
653 if hasHash(HashNames.MD4) {
654 wg.Add(1)
655 go func() {
656 startTime = makeTimestampNano()
657 d := md4.New()
658 d.Write(*content)
659 result.MD4 = hex.EncodeToString(d.Sum(nil))
660
661 if Trace {
662 printTrace(fmt.Sprintf("nanoseconds processing md4: %s: %d", filename, makeTimestampNano()-startTime))
663 }
664 wg.Done()
665 }()
666 }
667
668 if hasHash(HashNames.MD5) {
669 wg.Add(1)
670 go func() {
671 startTime = makeTimestampNano()
672 d := md5.New()
673 d.Write(*content)
674 result.MD5 = hex.EncodeToString(d.Sum(nil))
675
676 if Trace {
677 printTrace(fmt.Sprintf("nanoseconds processing md5: %s: %d", filename, makeTimestampNano()-startTime))
678 }
679 wg.Done()
680 }()
681 }
682
683 if hasHash(HashNames.SHA1) {
684 wg.Add(1)
685 go func() {
686 startTime = makeTimestampNano()
687 d := sha1.New()
688 d.Write(*content)
689 result.SHA1 = hex.EncodeToString(d.Sum(nil))
690
691 if Trace {
692 printTrace(fmt.Sprintf("nanoseconds processing sha1: %s: %d", filename, makeTimestampNano()-startTime))
693 }
694 wg.Done()
695 }()
696 }
697
698 if hasHash(HashNames.SHA256) {
699 wg.Add(1)
700 go func() {
701 startTime = makeTimestampNano()
702 d := sha256.New()
703 d.Write(*content)
704 result.SHA256 = hex.EncodeToString(d.Sum(nil))

Calls 3

makeTimestampNanoFunction · 0.85
hasHashFunction · 0.85
printTraceFunction · 0.85