Add proper error handling semantics to FileStream.
This commit is contained in:
parent
8c05696ed4
commit
32a8874a29
|
@ -19,13 +19,19 @@ type FileStream struct {
|
|||
filename string
|
||||
}
|
||||
|
||||
func NewFileStream(fileName string) *FileStream {
|
||||
func NewFileStream(fileName string) (*FileStream, error) {
|
||||
|
||||
buf := bytes.NewBuffer(nil)
|
||||
|
||||
f, _ := os.Open(fileName) // Error handling elided for brevity.
|
||||
io.Copy(buf, f) // Error handling elided for brevity.
|
||||
f.Close()
|
||||
f, err := os.Open(fileName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer f.Close()
|
||||
err = io.Copy(buf, f)
|
||||
if err != nil {
|
||||
return nil, er
|
||||
}
|
||||
|
||||
fs := new(FileStream)
|
||||
|
||||
|
@ -34,7 +40,7 @@ func NewFileStream(fileName string) *FileStream {
|
|||
|
||||
fs.InputStream = NewInputStream(s)
|
||||
|
||||
return fs
|
||||
return fs, nil
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue