HiveBrain v1.2.0
Get Started
← Back to all entries
snippetgoCritical

Create a io.Reader from a local file

Submitted by: @import:stackoverflow-api··
0
Viewed 0 times
fromreaderfilelocalcreate

Problem

I would like to open a local file, and return a io.Reader. The reason is that I need to feed a io.Reader to a library I am using, like:

func read(r io.Reader) (results []string) {

}

Solution

os.Open returns an io.Reader

http://play.golang.org/p/BskGT09kxL

package main

import (
    "fmt"
    "io"
    "os"
)

var _ io.Reader = (*os.File)(nil)

func main() {
    fmt.Println("Hello, playground")
}

Code Snippets

package main

import (
    "fmt"
    "io"
    "os"
)

var _ io.Reader = (*os.File)(nil)

func main() {
    fmt.Println("Hello, playground")
}

Context

Stack Overflow Q#25677235, score: 164

Revisions (0)

No revisions yet.