本文整理匯總了Golang中compress/flate.Writer.Flush方法的典型用法代碼示例。如果您正苦於以下問題:Golang Writer.Flush方法的具體用法?Golang Writer.Flush怎麽用?Golang Writer.Flush使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類compress/flate.Writer
的用法示例。
在下文中一共展示了Writer.Flush方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: readFile
func readFile(filePath string) (string, error) {
var buf []byte
var err error
var n int
var writer *flate.Writer
var encoder io.WriteCloser
var file *os.File
var data *bytes.Buffer = new(bytes.Buffer)
if file, err = os.Open(filePath); err != nil {
return "", err
}
defer file.Close()
encoder = ascii85.NewEncoder(data)
defer encoder.Close()
writer, err = flate.NewWriter(encoder, flate.BestCompression)
defer writer.Close()
buf = make([]byte, 8192)
err = nil
for {
if n, err = file.Read(buf); err != nil {
if err == io.EOF {
break
} else {
return "", err
}
}
if n == 8192 {
_, err = writer.Write(buf)
} else {
_, err = writer.Write(buf[:n])
}
if err != nil {
return "", err
}
}
if err = writer.Flush(); err != nil {
return "", err
}
return strconv.Quote(string(data.Bytes())), nil
}