Giter Club home page Giter Club logo

Comments (4)

Viq111 avatar Viq111 commented on September 22, 2024

Hi @zplzpl

There are some internal buffers usually on io.Writer and files so you need to properly close the objects to make sure the full data is written:

func panicOnError(err error) {
  if err != nil {
    panic(err)
  }
}

func main() {
  filename := "./test.zstd"
  file, err := os.OpenFile(filename, os.O_APPEND|os.O_WRONLY, 0644)
  panicOnError(err)
  defer file.Close()

  w := zstd.NewWriter(file)
  defer w.Close()
  _, err = w.Write([]byte("aaaaa"))
  panicOnError(err)
}

Hope this helps!

from zstd.

zplzpl avatar zplzpl commented on September 22, 2024

Oh, yes, I didn't do the correct closing operation.

I did what you said and it works.

But I have a problem, if the process crashes and exits, there is no correct close operation. Then there will be problems with continuing to write.

Is there any way to judge this zstd file, whether it was normally closed before?

If not closed properly, then create a new zstd file write.

from zstd.

Viq111 avatar Viq111 commented on September 22, 2024

Ah that makes sense. Hmmm, unfortunately usually those use cases are not directly handled by compression algorithm, they are usually implemented either at the file format layer (For examples, usually all databases have some sort of repair mechanism, see levelDB for example: https://godoc.org/github.com/syndtr/goleveldb/leveldb#Recover)
Or you could implement it with control codes and/or repair indexes (examples: CRCs: https://en.wikipedia.org/wiki/Error_detection_and_correction or https://en.wikipedia.org/wiki/Error_correction_code)

With that being said, zstd does implement an optional checksum control that is not surfaced yet with this library: #43. PR are welcomed if you want to implement it!

from zstd.

zplzpl avatar zplzpl commented on September 22, 2024

thank you

from zstd.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.