fileblob

package
v0.9.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 15, 2019 License: Apache-2.0 Imports: 14 Imported by: 300

Documentation

Overview

Package fileblob provides a blob implementation that uses the filesystem. Use OpenBucket to construct a blob.Bucket.

Blob keys are escaped before being used as filenames, and filenames are unescaped when they are passed back as blob keys during List. The escape algorithm is:

  • Alphanumeric characters (A-Z a-z 0-9) are not escaped.
  • Space (' '), dash ('-'), underscore ('_'), and period ('.') are not escaped.
  • Slash ('/') is always escaped to the OS-specific path separator character (os.PathSeparator).
  • All other characters are escaped similar to url.PathEscape: "%<hex UTF-8 byte>", with capital letters ABCDEF in the hex code.

Filenames that can't be unescaped due to invalid escape sequences (e.g., "%%"), or whose unescaped key doesn't escape back to the filename (e.g., "~", which unescapes to "~", which escapes back to "%7E" != "~"), aren't visible using fileblob.

Open URLs

For blob.Open URLs, fileblob registers for the scheme "file"; URLs start with "file://".

The URL's Path is used as the root directory; the URL's Host is ignored. If os.PathSeparator != "/", any leading "/" from the Path is dropped. 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".

As

fileblob does not support any types for As.

Example
package main

import (
	"io/ioutil"
	"log"
	"os"

	"gocloud.dev/blob/fileblob"
)

func main() {

	// For this example, 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.
	_, err = fileblob.OpenBucket(dir, nil)
	if err != nil {
		log.Fatal(err)
	}

}
Output:

Example (Open)
package main

import (
	"context"
	"io/ioutil"
	"log"
	"os"
	"path"

	"gocloud.dev/blob"
)

func main() {
	// For this example, create a temporary directory.
	dir, err := ioutil.TempDir("", "go-cloud-fileblob-example")
	if err != nil {
		log.Fatal(err)
	}
	defer os.RemoveAll(dir)

	_, err = blob.Open(context.Background(), path.Join("file://", dir))
	if err != nil {
		log.Fatal(err)
	}

}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func OpenBucket

func OpenBucket(dir string, opts *Options) (*blob.Bucket, error)

OpenBucket creates a *blob.Bucket backed by the filesystem and rooted at dir, which must exist. See the package documentation for an example.

Types

type Options

type Options struct{}

Options sets options for constructing a *blob.Bucket backed by fileblob.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL