Home Download Docs Code Community
     1	/*
     2	Copyright 2014 The Perkeep Authors
     3	
     4	Licensed under the Apache License, Version 2.0 (the "License");
     5	you may not use this file except in compliance with the License.
     6	You may obtain a copy of the License at
     7	
     8	     http://www.apache.org/licenses/LICENSE-2.0
     9	
    10	Unless required by applicable law or agreed to in writing, software
    11	distributed under the License is distributed on an "AS IS" BASIS,
    12	WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13	See the License for the specific language governing permissions and
    14	limitations under the License.
    15	*/
    16	
    17	// Package dir implements the blobserver Storage interface for a directory,
    18	// detecting whether the directory is file-per-blob (localdisk) or diskpacked.
    19	// If neither, it initializes diskpacked.
    20	package dir // import "perkeep.org/pkg/blobserver/dir"
    21	
    22	import (
    23		"perkeep.org/pkg/blobserver"
    24		"perkeep.org/pkg/blobserver/diskpacked"
    25		"perkeep.org/pkg/blobserver/localdisk"
    26	)
    27	
    28	// New returns a new blobserver Storage implementation, storing blobs in the provided dir.
    29	// If dir has an index.kv file, a diskpacked implementation is returned.
    30	func New(dir string) (blobserver.Storage, error) {
    31		if v, err := diskpacked.IsDir(dir); err != nil {
    32			return nil, err
    33		} else if v {
    34			return diskpacked.New(dir)
    35		}
    36		if v, err := localdisk.IsDir(dir); err != nil {
    37			return nil, err
    38		} else if v {
    39			return localdisk.New(dir)
    40		}
    41		return diskpacked.New(dir)
    42	}
Website layout inspired by memcached.
Content by the authors.