golang / snappy

The Snappy compression format in the Go programming language.
BSD 3-Clause "New" or "Revised" License
1.52k stars 163 forks source link

I can't attach the snappy.Reader to a string.. #34

Open paidir opened 8 years ago

paidir commented 8 years ago

code:

    stringReader := strings.NewReader(pbMsg.GetBody().GetReqData().GetContent())
    snappyReader := snappy.NewReader(stringReader)
    rNum, _ := snappyReader.Read(conBytes)

line:pbMsg.GetBody().GetReqData().GetContent() return a string . when using the stringReader as the paramater , the rNum is 0, why? 3q very much

nigeltao commented 8 years ago

The first step is: don't ignore the error that snappyReader.Read is returning.

After that, I'm only guessing, but there is a difference between the block Snappy format, and the streaming Snappy format. The streaming format is the block format plus a framing header. The snappy.Reader is for the streaming format, but most people use the block format. Try this instead:

decoded, err := snappy.Decode(nil, []byte(pbMsg.GetBody().GetReqData().GetContent()))