Browse Source

Expose DataCompressor struct attributes (#192)

bsord 6 years ago
parent
commit
51f7dda326
1 changed files with 13 additions and 13 deletions
  1. 13 13
      backends/p_compressor.go

+ 13 - 13
backends/p_compressor.go

@@ -32,10 +32,10 @@ func init() {
 
 
 // compressedData struct will be compressed using zlib when printed via fmt
 // compressedData struct will be compressed using zlib when printed via fmt
 type DataCompressor struct {
 type DataCompressor struct {
-	extraHeaders []byte
-	data         *bytes.Buffer
+	ExtraHeaders []byte
+	Data         *bytes.Buffer
 	// the pool is used to recycle buffers to ease up on the garbage collector
 	// the pool is used to recycle buffers to ease up on the garbage collector
-	pool *sync.Pool
+	Pool *sync.Pool
 }
 }
 
 
 // newCompressedData returns a new CompressedData
 // newCompressedData returns a new CompressedData
@@ -49,44 +49,44 @@ func newCompressor() *DataCompressor {
 		},
 		},
 	}
 	}
 	return &DataCompressor{
 	return &DataCompressor{
-		pool: &p,
+		Pool: &p,
 	}
 	}
 }
 }
 
 
 // Set the extraheaders and buffer of data to compress
 // Set the extraheaders and buffer of data to compress
 func (c *DataCompressor) set(b []byte, d *bytes.Buffer) {
 func (c *DataCompressor) set(b []byte, d *bytes.Buffer) {
-	c.extraHeaders = b
-	c.data = d
+	c.ExtraHeaders = b
+	c.Data = d
 }
 }
 
 
 // String implements the Stringer interface.
 // String implements the Stringer interface.
 // Can only be called once!
 // Can only be called once!
 // This is because the compression buffer will be reset and compressor will be returned to the pool
 // This is because the compression buffer will be reset and compressor will be returned to the pool
 func (c *DataCompressor) String() string {
 func (c *DataCompressor) String() string {
-	if c.data == nil {
+	if c.Data == nil {
 		return ""
 		return ""
 	}
 	}
 	//borrow a buffer form the pool
 	//borrow a buffer form the pool
-	b := c.pool.Get().(*bytes.Buffer)
+	b := c.Pool.Get().(*bytes.Buffer)
 	// put back in the pool
 	// put back in the pool
 	defer func() {
 	defer func() {
 		b.Reset()
 		b.Reset()
-		c.pool.Put(b)
+		c.Pool.Put(b)
 	}()
 	}()
 
 
 	var r *bytes.Reader
 	var r *bytes.Reader
 	w, _ := zlib.NewWriterLevel(b, zlib.BestSpeed)
 	w, _ := zlib.NewWriterLevel(b, zlib.BestSpeed)
-	r = bytes.NewReader(c.extraHeaders)
+	r = bytes.NewReader(c.ExtraHeaders)
 	_, _ = io.Copy(w, r)
 	_, _ = io.Copy(w, r)
-	_, _ = io.Copy(w, c.data)
+	_, _ = io.Copy(w, c.Data)
 	_ = w.Close()
 	_ = w.Close()
 	return b.String()
 	return b.String()
 }
 }
 
 
 // clear it, without clearing the pool
 // clear it, without clearing the pool
 func (c *DataCompressor) clear() {
 func (c *DataCompressor) clear() {
-	c.extraHeaders = []byte{}
-	c.data = nil
+	c.ExtraHeaders = []byte{}
+	c.Data = nil
 }
 }
 
 
 func Compressor() Decorator {
 func Compressor() Decorator {