Skip to content

Commit

Permalink
Make code shorter
Browse files Browse the repository at this point in the history
  • Loading branch information
fasmat committed Sep 19, 2023
1 parent b813d79 commit ee39a22
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions activation/nipost_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package activation

import (
"encoding/binary"
"errors"
"fmt"
"hash/crc64"
"io"
Expand All @@ -28,18 +27,17 @@ func write(path string, data []byte) error {
if err != nil {
return fmt.Errorf("create temporary file %s: %w", tmpName, err)

Check warning on line 28 in activation/nipost_state.go

View check run for this annotation

Codecov / codecov/patch

activation/nipost_state.go#L28

Added line #L28 was not covered by tests
}
defer tmp.Close()

checksum := crc64.New(crc64.MakeTable(crc64.ISO))
w := io.MultiWriter(tmp, checksum)
if _, err := w.Write(data); err != nil {
err = errors.Join(err, tmp.Close())
return fmt.Errorf("write data %v: %w", tmp.Name(), err)
}

crc := make([]byte, crc64.Size)
binary.BigEndian.PutUint64(crc, checksum.Sum64())
if _, err := tmp.Write(crc); err != nil {
err = errors.Join(err, tmp.Close())
return fmt.Errorf("write checksum %s: %w", tmp.Name(), err)
}

Expand Down

0 comments on commit ee39a22

Please sign in to comment.