wip
parent
ce5bf71f6b
commit
622c173264
|
|
@ -3,10 +3,13 @@ package ledger
|
|||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/fs"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"unicode"
|
||||
|
|
@ -33,7 +36,27 @@ func (files Files) TempGetLastNLines(n int) ([]string, error) {
|
|||
}
|
||||
|
||||
func (files Files) TempSetLastNLines(n int, lines []string) error {
|
||||
panic("e")
|
||||
p := files.paths()[0]
|
||||
w, err := ioutil.TempFile(os.TempDir(), path.Base(p))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer w.Close()
|
||||
|
||||
r, err := os.Open(p)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer r.Close()
|
||||
|
||||
if _, err := peekLastNLines(w, r, n); err != nil {
|
||||
return err
|
||||
}
|
||||
for i := range lines {
|
||||
fmt.Fprintln(w, lines[i])
|
||||
}
|
||||
|
||||
return errors.New(w.Name())
|
||||
}
|
||||
|
||||
func peekLastNLines(w io.Writer, r *bufio.Reader, n int) ([]string, error) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue