LEFT | RIGHT |
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 package flate | 5 package flate |
6 | 6 |
7 import ( | 7 import ( |
8 "io" | 8 "io" |
9 "math" | 9 "math" |
10 ) | 10 ) |
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
425 } | 425 } |
426 return &dw, nil | 426 return &dw, nil |
427 } | 427 } |
428 | 428 |
429 // NewWriterDict is like NewWriter but initializes the new | 429 // NewWriterDict is like NewWriter but initializes the new |
430 // Writer with a preset dictionary. The returned Writer behaves | 430 // Writer with a preset dictionary. The returned Writer behaves |
431 // as if the dictionary had been written to it without producing | 431 // as if the dictionary had been written to it without producing |
432 // any compressed output. The compressed data written to w | 432 // any compressed output. The compressed data written to w |
433 // can only be decompressed by a Reader initialized with the | 433 // can only be decompressed by a Reader initialized with the |
434 // same dictionary. | 434 // same dictionary. |
435 // | |
436 // If level is in the range [-1, 9] then the error returned will be nil. | |
437 // Otherwise the error returned will be non-nil. | |
438 func NewWriterDict(w io.Writer, level int, dict []byte) (*Writer, error) { | 435 func NewWriterDict(w io.Writer, level int, dict []byte) (*Writer, error) { |
439 dw := &dictWriter{w, false} | 436 dw := &dictWriter{w, false} |
440 zw, err := NewWriter(dw, level) | 437 zw, err := NewWriter(dw, level) |
441 if err != nil { | 438 if err != nil { |
442 return nil, err | 439 return nil, err |
443 } | 440 } |
444 zw.Write(dict) | 441 zw.Write(dict) |
445 zw.Flush() | 442 zw.Flush() |
446 dw.enabled = true | 443 dw.enabled = true |
447 return zw, err | 444 return zw, err |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
481 func (w *Writer) Flush() error { | 478 func (w *Writer) Flush() error { |
482 // For more about flushing: | 479 // For more about flushing: |
483 // http://www.bolet.org/~pornin/deflate-flush.html | 480 // http://www.bolet.org/~pornin/deflate-flush.html |
484 return w.d.syncFlush() | 481 return w.d.syncFlush() |
485 } | 482 } |
486 | 483 |
487 // Close flushes and closes the writer. | 484 // Close flushes and closes the writer. |
488 func (w *Writer) Close() error { | 485 func (w *Writer) Close() error { |
489 return w.d.close() | 486 return w.d.close() |
490 } | 487 } |
LEFT | RIGHT |