Commit b664d749 authored by Kirill Smelkov's avatar Kirill Smelkov

go/zodb/fs1: Factor-out noEOF and okEOF into common place (-> internal/xio)

We will need to use those utilities for ZEO and NEO.
parent 58689cb6
// Copyright (C) 2017 Nexedi SA and Contributors. // Copyright (C) 2017-2020 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com> // Kirill Smelkov <kirr@nexedi.com>
// //
// This program is free software: you can Use, Study, Modify and Redistribute // This program is free software: you can Use, Study, Modify and Redistribute
...@@ -28,6 +28,23 @@ import ( ...@@ -28,6 +28,23 @@ import (
"lab.nexedi.com/kirr/neo/go/internal/xcontext" "lab.nexedi.com/kirr/neo/go/internal/xcontext"
) )
// NoEOF returns err, but changes io.EOF -> io.ErrUnexpectedEOF.
func NoEOF(err error) error {
if err == io.EOF {
err = io.ErrUnexpectedEOF
}
return err
}
// EOFok returns err, but changes io.EOF -> nil.
func EOFok(err error) error {
if err == io.EOF {
err = nil
}
return err
}
// CloseWhenDone arranges for c to be closed either when ctx is cancelled or // CloseWhenDone arranges for c to be closed either when ctx is cancelled or
// surrounding function returns. // surrounding function returns.
// //
......
// Copyright (C) 2017 Nexedi SA and Contributors. // Copyright (C) 2017-2020 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com> // Kirill Smelkov <kirr@nexedi.com>
// //
// This program is free software: you can Use, Study, Modify and Redistribute // This program is free software: you can Use, Study, Modify and Redistribute
...@@ -20,27 +20,15 @@ ...@@ -20,27 +20,15 @@
package fs1 package fs1
import ( import (
"io"
"os" "os"
"lab.nexedi.com/kirr/neo/go/internal/xio"
"lab.nexedi.com/kirr/go123/xbufio" "lab.nexedi.com/kirr/go123/xbufio"
) )
// noEOF returns err, but changes io.EOF -> io.ErrUnexpectedEOF // noEOF and okEOF are syntactic sugar over xio.NoEOF and xio.EOFok.
func noEOF(err error) error { func noEOF(err error) error { return xio.NoEOF(err) }
if err == io.EOF { func okEOF(err error) error { return xio.EOFok(err) }
err = io.ErrUnexpectedEOF
}
return err
}
// okEOF returns err, but changes io.EOF -> nil
func okEOF(err error) error {
if err == io.EOF {
err = nil
}
return err
}
// record reading routines work on abstract file-like interfaces. // record reading routines work on abstract file-like interfaces.
// when they report e.g. decoding error, if reader has name, e.g. as os.File // when they report e.g. decoding error, if reader has name, e.g. as os.File
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment