wip
This commit is contained in:
@@ -3,10 +3,13 @@ package ledger
|
|||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sort"
|
"sort"
|
||||||
"unicode"
|
"unicode"
|
||||||
@@ -33,7 +36,27 @@ func (files Files) TempGetLastNLines(n int) ([]string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (files Files) TempSetLastNLines(n int, lines []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) {
|
func peekLastNLines(w io.Writer, r *bufio.Reader, n int) ([]string, error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user