Documentation ¶
Overview ¶
Package fileblob provides a blob implementation that uses the filesystem. Use OpenBucket to construct a *blob.Bucket.
Open URLs ¶
For blob.Open URLs, fileblob registers for the scheme "file"; URLs start with "file://" like "file:///path/to/directory". For full details, see URLOpener.
Escaping ¶
Go CDK supports all UTF-8 strings; to make this work with providers lacking full UTF-8 support, strings must be escaped (during writes) and unescaped (during reads). The following escapes are performed for fileblob:
- Blob keys: ASCII characters 0-31 are escaped to "__0x<hex>__". If os.PathSeparator != "/", it is also escaped. Additionally, the "/" in "../", the trailing "/" in "//", and a trailing "/" is key names are escaped in the same way.
As ¶
fileblob exposes the following types for As:
- Error: *os.PathError
Example ¶
package main import ( "context" "fmt" "io/ioutil" "log" "os" "gocloud.dev/blob/fileblob" ) func main() { // Create a temporary directory. dir, err := ioutil.TempDir("", "go-cloud-fileblob-example") if err != nil { log.Fatal(err) } defer os.RemoveAll(dir) // Create a file-based bucket. b, err := fileblob.OpenBucket(dir, nil) if err != nil { log.Fatal(err) } // Now we can use b to read or write files to the container. ctx := context.Background() err = b.WriteAll(ctx, "my-key", []byte("hello world"), nil) if err != nil { log.Fatal(err) } data, err := b.ReadAll(ctx, "my-key") if err != nil { log.Fatal(err) } fmt.Println(string(data)) }
Output: hello world
Example (Open) ¶
package main import ( "context" "fmt" "io/ioutil" "log" "os" "path" "gocloud.dev/blob" ) func main() { // Create a temporary directory. dir, err := ioutil.TempDir("", "go-cloud-fileblob-example") if err != nil { log.Fatal(err) } defer os.RemoveAll(dir) // Open creates a *blob.Bucket from a URL. ctx := context.Background() b, err := blob.OpenBucket(ctx, path.Join("file://", dir)) if err != nil { log.Fatal(err) } // Now we can use b to read or write files to the container. err = b.WriteAll(ctx, "my-key", []byte("hello world"), nil) if err != nil { log.Fatal(err) } data, err := b.ReadAll(ctx, "my-key") if err != nil { log.Fatal(err) } fmt.Println(string(data)) }
Output: hello world
Index ¶
Examples ¶
Constants ¶
const Scheme = "file"
Scheme is the URL scheme fileblob registers its URLOpener under on blob.DefaultMux.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Options ¶
type Options struct{}
Options sets options for constructing a *blob.Bucket backed by fileblob.
type URLOpener ¶ added in v0.10.0
type URLOpener struct{}
URLOpener opens file bucket URLs like "file:///foo/bar/baz".
func (*URLOpener) OpenBucketURL ¶ added in v0.10.0
OpenBucketURL opens the file bucket at the URL's path. The URL's host is ignored. If os.PathSeparator != "/", any leading "/" from the path is dropped and remaining '/' characters are converted to os.PathSeparator. No query options are supported. Examples:
- file:///a/directory -> Passes "/a/directory" to OpenBucket.
- file://localhost/a/directory -> Also passes "/a/directory".
- file:///c:/foo/bar -> Passes "c:\foo\bar".
- file://localhost/c:/foo/bar -> Also passes "c:\foo\bar".