You need to enable JavaScript to run this app.
Torch Object Storage

Torch Object Storage

Copy page
Download PDF
Checking data integrity
Verifying the integrity of downloaded objects
Copy page
Download PDF
Verifying the integrity of downloaded objects
This topic illustrates the validation workflow and provides sample codes for validating the integrity of downloaded objects using the CRC-64 algorithm.​
How it works​
In scenarios where an entire object is downloaded in a single operation, the client calculates a CRC-64 checksum while receiving the data. This value is then compared to the CRC-64 checksum stored on the server to ensure the integrity of the downloaded data.​
When an object is downloaded in segments using the Range header, a composite checksum is calculated based on the individual checksums of each segment. This value is then compared to the checksum of the entire object that the server returns to ensure the integrity of the final downloaded object.​
Flowchart​
​​​
​
Code examples​
​
Golang
Python
​
​
package main​
​
import (​
"context"​
"hash"​
"io"​
"io/ioutil"​
​
"github.com/volcengine/ve-tos-golang-sdk/v2/tos"​
)​
​
type crc64Reader struct {​
r io.Reader​
h hash.Hash64​
}​
​
func (cr *crc64Reader) Read(p []byte) (n int, err error) {​
n, err = cr.r.Read(p)​
cr.h.Write(p[:n])​
return n, err​
}​
​
func main() {​
var (​
accessKey = "your access key"​
secretKey = "your secret key"​
endpoint = "your endpoint"​
region = "your region"​
bucket = "bucketname"​
key = "objectname"​
)​
client, err := tos.NewClientV2(endpoint, tos.WithRegion(region), tos.WithCredentials(tos.NewStaticCredentials(accessKey, secretKey)))​
if err != nil {​
panic(err)​
}​
​
output, err := client.GetObjectV2(context.Background(), &tos.GetObjectV2Input{​
Bucket: bucket,​
Key: key,​
})​
​
defer output.Content.Close()​
p := make([]byte, 1024)​
crc64Hash := tos.NewCRC(tos.DefaultCrcTable(), 0)​
reader := &crc64Reader{​
r: output.Content,​
h: crc64Hash,​
}​
for {​
_, err = reader.Read(p)​
if err != nil {​
if err == io.EOF{​
break​
}​
panic(err)​
}​
}​
​
if output.HashCrc64ecma != crc64Hash.Sum64() {​
panic("crc64 not match")​
}​
}​
​
​
Last updated: 2026.08.25 10:39:45