mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-09-07 09:05:55 +00:00
refactored file download to support large files
This commit is contained in:
parent
521542bbe1
commit
a765dd8bc5
2 changed files with 30 additions and 6 deletions
|
|
@ -20,12 +20,37 @@ func TestRemote(t *testing.T) {
|
|||
So(err, ShouldEqual, nil)
|
||||
content, _ := ssh.Run("date", false)
|
||||
ssh.CopyTo(strings.NewReader(content), "uploadfile")
|
||||
results, _ := ssh.CopyFrom("uploadfile")
|
||||
ok := bytes.Equal([]byte(content), results)
|
||||
var out bytes.Buffer
|
||||
ssh.CopyFrom("uploadfile", &out)
|
||||
|
||||
ok := bytes.Equal([]byte(content), out.Bytes())
|
||||
So(ok, ShouldEqual, true)
|
||||
} else {
|
||||
fmt.Println("No credentials so SSH Test ignored")
|
||||
So(true, ShouldEqual, true)
|
||||
}
|
||||
})
|
||||
/*
|
||||
Convey("BigFile", t, func() {
|
||||
ssh, err := New("50.16.204.123:22", "todd", "id_dsa")
|
||||
|
||||
fo, err := os.Create("outbin")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
// close fo on exit and check for its returned error
|
||||
defer func() {
|
||||
if err := fo.Close(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}()
|
||||
// make a write buffer
|
||||
w := bufio.NewWriter(fo)
|
||||
ssh.CopyFrom("pilosa-cruncher", w)
|
||||
if err = w.Flush(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
})
|
||||
*/
|
||||
}
|
||||
|
|
|
|||
|
|
@ -117,15 +117,14 @@ func (self *SSH) CopyTo(content io.Reader, dest_name string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
func (self *SSH) CopyFrom(dest_name string) ([]byte, error) {
|
||||
func (self *SSH) CopyFrom(dest_name string, out io.Writer) error {
|
||||
|
||||
session, _ := self.client.NewSession()
|
||||
defer session.Close()
|
||||
var b bytes.Buffer
|
||||
session.Stdout = &b
|
||||
session.Stdout = out
|
||||
session.Run(fmt.Sprintf("/bin/cat %s", dest_name))
|
||||
|
||||
return b.Bytes(), nil
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue