From 181ac22e08097565cf57140f4b430f1213f5e0b6 Mon Sep 17 00:00:00 2001 From: MoZhonghua Date: Thu, 23 Jun 2016 16:59:02 +0800 Subject: [PATCH] Reader/Writer should implement Close() to free convertor --- reader.go | 6 ++++++ writer.go | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/reader.go b/reader.go index 2835ce6..948d9d0 100644 --- a/reader.go +++ b/reader.go @@ -5,6 +5,7 @@ import ( "syscall" ) +// This implements io.ReadCloser interface type Reader struct { source io.Reader converter *Converter @@ -61,6 +62,11 @@ func (this *Reader) fillBuffer() { } } +// Must be called to free memory +func (this *Reader) Close() error { + return this.converter.Close() +} + // implement the io.Reader interface func (this *Reader) Read(p []byte) (n int, err error) { // checks for when we have no data diff --git a/writer.go b/writer.go index db007eb..bc3a390 100644 --- a/writer.go +++ b/writer.go @@ -2,6 +2,7 @@ package iconv import "io" +// This implements io.WriteCloser interface type Writer struct { destination io.Writer converter *Converter @@ -58,6 +59,11 @@ func (this *Writer) emptyBuffer() { } } +// Must be called to free memory +func (this *Writer) Close() error { + return this.converter.Close() +} + // implement the io.Writer interface func (this *Writer) Write(p []byte) (n int, err error) { // write data into our internal buffer