Skip to content

Instantly share code, notes, and snippets.

@MasterGroosha
Last active July 15, 2019 16:24
Show Gist options
  • Save MasterGroosha/2de4002dac47580f0eb1d91d6818dfd5 to your computer and use it in GitHub Desktop.
Save MasterGroosha/2de4002dac47580f0eb1d91d6818dfd5 to your computer and use it in GitHub Desktop.
package main
import (
"bytes"
"compress/zlib"
"encoding/binary"
"fmt"
//"io"
"io/ioutil"
//"os"
)
func main() {
datafile, err := ioutil.ReadFile("D:\\Data\\kav\\DOCSREAD\\0000000001.data")
if err != nil {
panic(err)
}
//doc := Document{}
datafileBytes := bytes.NewReader(datafile)
binDocID := make([]byte, 8)
binDocSize := make([]byte, 4)
// Сдвигаемся по файлу
datafileBytes.Read(binDocID)
datafileBytes.Read(binDocSize)
datafileBytes.Read(make([]byte, 2)) // ConstructorVersion
datafileBytes.Read(make([]byte, 2)) // ArchivedFlag
var docID uint64
var docSize int32
buf := bytes.NewBuffer(binDocSize)
binary.Read(buf, binary.LittleEndian, &docSize)
content := make([]byte, docSize)
zlibData, err := zlib.NewReader(datafileBytes)
zlibData.Read(content)
buf = bytes.NewBuffer(binDocID)
binary.Read(buf, binary.LittleEndian, &docID)
fmt.Println("Document id", docID)
fmt.Println("Document size", docSize)
//fmt.Println("Document len:", len(content))
//fmt.Println(content)
//io.Copy(os.Stdout, zlibData)
var fieldType int16
var fieldLength int32
var fieldValue []byte
for remaining := len(content); remaining >= 0; {
content.Read(fieldType)
content.Read(fieldLength)
fieldValue = make([]byte, fieldLength)
}
//newf, _ := os.Open("/home/groosha/testzlib/test.zlib")
//defer newf.Close()
/*
b := bytes.NewReader(datafile)
r, err := zlib.NewReader(b)
docID := make(int64)
somebytes := make([]byte, 2)
r.Read(somebytes) // Читаем по два байта!
// r.Read(somebytes)
fmt.Println(string(somebytes))
io.Copy(os.Stdout, r)
r.Close()
*/
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment