1 package httpbuffer 2 3 import ( 4 "io" 5 6 "vimagination.zapto.org/httpencoding" 7 ) 8 9 var encodings = map[httpencoding.Encoding]Encoding{ 10 "": identity{}, 11 } 12 13 type identity struct{} 14 15 func (identity) Open(w io.Writer) io.Writer { 16 return w 17 } 18 19 func (identity) Close(io.Writer) {} 20 21 func (identity) Name() string { 22 return "" 23 } 24 25 // Encoding represents a type that applies a Coding to a byte stream. 26 type Encoding interface { 27 // Open takes a buffer and returns an encoder-wrapped buffer. 28 Open(io.Writer) io.Writer 29 30 // Close returns the encoder-wrapped buffer to flush/close and release 31 // resources. 32 Close(io.Writer) 33 34 // Name returns the identifier for the encoding algorithm. 35 Name() string 36 } 37 38 // Register registers the encoding for the buffers to use. Should not be used 39 // passed initialisation. 40 func Register(e Encoding) { 41 encodings[httpencoding.Encoding(e.Name())] = e 42 } 43