pairtree

package
v2.0.0-a6 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2022 License: BSD-3-Clause Imports: 2 Imported by: 0

README

Pairtree

This is a library for translate a UTF-8 string to/from a pairtree notation. This is typically used in storing things on disc (e.g. repository filesystems). This code is based on the specification found at OCLC's Confluence website which is cited on the OCFL wiki. A draft IETF spec by John Kunze et el. can be found at https://datatracker.ietf.org/doc/html/draft-kunze-pairtree-01.

NOTE: If you are looking for Python or Java implementedations they can befound at PyPi and on GitHub

This Go package is managed as a sub-module of the dataset project developed at Caltech Library.

Features

  • Set() will let you set the path separator
    • Separator is a readonly value of the file separator used by Encode() and Decode()
  • Encode() will encode the provided string as a pairtree path
  • Decode() will decode a pairtree path returning the unencoded string

Example

    import (
        "fmt"
        "os"

        "github.com/caltechlibrary/pairtree"
    )

    func main() {
        key := "12mIEERD11"
        fmt.Printf("Key: %q\n", key)
        pairPath := pairtree.Encode(key)
        fmt.Printf("Endoded key %q -> %q\n", key, pairPath)
        key = Decode(pairPath)
        fmt.Printf("Decoded path %q -> %q\n", pairPath, key)
    }

Documentation

Overview

pairtree.go implements encoding/decoding of object identifiers and pairtree paths (paths) per https://confluence.ucop.edu/download/attachments/14254128/PairtreeSpec.pdf?version=2&modificationDate=1295552323000&api=v2

Author R. S. Doiel, <rsdoiel@library.caltech.edu>

Copyright (c) 2022, Caltech All rights not granted herein are expressly reserved by Caltech.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Index

Constants

This section is empty.

Variables

View Source
var (
	// Separator is the path separator used for your pairtree.
	// by default it is set to your operating system's path separator.
	Separator = '/'
)

Functions

func Decode

func Decode(src string) string

Decode takes a pairtree path and returns the original string representation

func Encode

func Encode(src string) string

Encode takes a string and encodes it as a pairtree path.

func Get

func Get() rune

Get will return the current separator in use in the package

func Set

func Set(c rune)

Set will set the separator used in encoding and decoding the Pairtree path

Types

This section is empty.

Jump to

Keyboard shortcuts

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