package steno

import (
	"bufio"
	"os"
)

type IO struct {
	writer *bufio.Writer
	codec Codec
}

func NewIOSink(file *os.File) *IO {
	writer := bufio.NewWriter(file)

	io := new(IO)
	io.writer = writer

	return io
}

func NewFileSink(path string) *IO {
	file, err := os.OpenFile(path, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0666)
	if err != nil {
		panic(err)
	}

	return NewIOSink(file)
}

func (io *IO) AddRecord(record *Record) {
	msg := io.codec.EncodeRecord(record)
	io.writer.WriteString(msg)
}


func (io *IO) Flush() {
	io.writer.Flush()
}

func (io *IO) SetCodec(codec Codec) {
	io.codec = codec
}

func (io *IO) GetCodec() Codec {
	return io.codec
}

package steno

import (
	"bufio"
	"os"
)

type IOSink struct {
	writer *bufio.Writer
	codec Codec
}

func NewIOSink(file *os.File) *IOSink {
	writer := bufio.NewWriter(file)

	ioSink := new(IOSink)
	ioSink.writer = writer

	return ioSink
}

func NewFileSink(path string) *IOSink {
	file, err := os.OpenFile(path, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0666)
	if err != nil {
		panic(err)
	}

	return NewIOSink(file)
}

func (ioSink *IOSink) AddRecord(record *Record) {
	msg := ioSink.codec.EncodeRecord(record)
	ioSink.writer.WriteString(msg)
}


func (ioSink *IOSink) Flush() {
	ioSink.writer.Flush()
}

func (ioSink *IOSink) SetCodec(codec Codec) {
	ioSink.codec = codec
}

func (ioSink *IOSink) GetCodec() Codec {
	return ioSink.codec
}

Rename struct IO to IOSink
Rename struct IO to IOSink

Change-Id: Icbbc5215648f4f19cc834ca3234e3e1294fd3471
