Skip to content
This repository was archived by the owner on Mar 30, 2022. It is now read-only.

Support reading files via io.Reader #27

Open
dominik-lekse opened this issue Mar 25, 2022 · 0 comments
Open

Support reading files via io.Reader #27

dominik-lekse opened this issue Mar 25, 2022 · 0 comments

Comments

@dominik-lekse
Copy link
Contributor

Provide a function which allows to open files from the remote server and read from them via an io.Reader.

Description

The proposed function ReceiveOpen returns a FileInfo to the caller similar to Receive. The difference to Receive is, that writing to an io.Writer provided by the caller, the caller gets an io.Reader.

The main advantage is that it provides the consumer more control over reading process. This would allow better integration of go-scp with other golang modules. For example, the io.Reader can be wrapped in high level Reader implementations provided by the io package.

Proposed changes

Add the function ReceiveOpen:

// ReceiveOpen returns a FileInfo and a ReadCloser
func (*SCP) ReceiveOpen(srcFile string) (*FileInfo, io.ReadCloser, error)

Example usage

// Open file on remote server
reader, fileInfo, err := scp.NewSCP(c).ReceiveOpen(remotePath)
defer reader.Close()
if err != nil {
    panic(err)
}

// Read file data into slice
data, err := ioutil.ReadAll(reader)
if err != nil {
    panic(err)
}
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant