notmuch: don't read the full file into memory
This commit is contained in:
parent
077063ba4b
commit
db6848fe1b
|
@ -3,10 +3,9 @@
|
||||||
package notmuch
|
package notmuch
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bufio"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"git.sr.ht/~sircmpwn/aerc/models"
|
"git.sr.ht/~sircmpwn/aerc/models"
|
||||||
|
@ -22,7 +21,7 @@ type Message struct {
|
||||||
db *notmuch.DB
|
db *notmuch.DB
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewReader reads a message into memory and returns an io.Reader for it.
|
// NewReader returns a reader for a message
|
||||||
func (m *Message) NewReader() (io.Reader, error) {
|
func (m *Message) NewReader() (io.Reader, error) {
|
||||||
name, err := m.Filename()
|
name, err := m.Filename()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -32,12 +31,7 @@ func (m *Message) NewReader() (io.Reader, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer f.Close()
|
return bufio.NewReader(f), nil
|
||||||
b, err := ioutil.ReadAll(f)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return bytes.NewReader(b), nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// MessageInfo populates a models.MessageInfo struct for the message.
|
// MessageInfo populates a models.MessageInfo struct for the message.
|
||||||
|
|
Loading…
Reference in New Issue