fileexporter and zstd compression enabled - tool to uncompress these files? #27837
Replies: 2 comments
-
I was wondering the same. I tried to uncompress it using the zstd command line tool on my Ubuntu machine, but I get the error message "unsupported format". EDIT: Thanks for the hint, after removing the 4 extra bytes its also working with the zstd command line tool |
Beta Was this translation helpful? Give feedback.
-
Because of curiosity I realized a small tool (in Java) considering the 4 extra bytes as described in the documentation. But I'm still interested in answers to my original questions ;-). package main
import (
"fmt"
"io"
"os"
"github.com/klauspost/compress/zstd"
)
func processFile(inputFilePath string, outputFilePath string) error {
file, err := os.Open(inputFilePath)
if err != nil {
return err
}
defer file.Close()
var outputStream io.Writer
if outputFilePath != "" {
outputFile, err := os.Create(outputFilePath)
if err != nil {
return err
}
defer outputFile.Close()
outputStream = outputFile
} else {
outputStream = os.Stdout
}
bufferedInputStream := zstd.NewReader(file)
for {
// Read the first 4 bytes to get the length of the following data
lengthBytes := make([]byte, 4)
_, err := io.ReadFull(bufferedInputStream, lengthBytes)
if err == io.EOF {
break // End of file reached
} else if err != nil {
return err
}
// Convert the length bytes to an integer
dataLength := int(ByteToUint32(lengthBytes))
// Read the next 'dataLength' bytes
data := make([]byte, dataLength)
_, err = io.ReadFull(bufferedInputStream, data)
if err != nil {
return err
}
// Decompress the data using Zstd
zstdReader, err := zstd.NewReader(bytes.NewReader(data))
if err != nil {
return err
}
defer zstdReader.Close()
// Write or print the decompressed data
buffer := make([]byte, 1024)
for {
len, err := zstdReader.Read(buffer)
if err == io.EOF {
break
} else if err != nil {
return err
}
_, err = outputStream.Write(buffer[:len])
if err != nil {
return err
}
}
}
return nil
}
func main() {
if len(os.Args) < 2 || len(os.Args) > 3 {
fmt.Println("Usage: go run main.go <inputFilePath> [outputFilePath]")
os.Exit(1)
}
inputFilePath := os.Args[1]
outputFilePath := ""
if len(os.Args) == 3 {
outputFilePath = os.Args[2]
}
err := processFile(inputFilePath, outputFilePath)
if err != nil {
fmt.Println("Error:", err)
os.Exit(1)
}
}
// ByteToUint32 converts a slice of 4 bytes to a uint32.
func ByteToUint32(b []byte) uint32 {
return uint32(b[0])<<24 | uint32(b[1])<<16 | uint32(b[2])<<8 | uint32(b[3])
} |
Beta Was this translation helpful? Give feedback.
-
As far as I understand what is in [FileExporter Readme] file (https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/exporter/fileexporter), 4 extra bytes are added for each compressed data-chunk in the resulting files.
Is there a tool that is able to create uncompressed file out of it? Is there a client utility planned or will only the File Receiver provide this functionality in the future?
Beta Was this translation helpful? Give feedback.
All reactions