parcels

package module
v0.0.0-...-cce7ac9 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2016 License: MIT Imports: 6 Imported by: 1

README

go-parcels

A library that provides a convenient immutable way of passing around a piece of data, with easy ways of getting that data as []byte, io.Reader, []rune, or string types, for the Go programming language.

Documention

Online documentation, which includes examples, can be found at: http://godoc.org/github.com/reiver/go-parcels

GoDoc

Example #1a

import (
	"github.com/reiver/go-parcels"
)

// ...

parcel := parcels.ParcelFromString("This is some content!")

asBytes  := parcel.Bytes()
asReader := parcel.Reader()
asRunes  := parcel.Runes()
asString := parcel.String()

n, err := parcel.WriteTo(writer)

Example 1b

import (
	"github.com/reiver/go-parcels"
)

// ...

parcel := parcels.ParcelFromBytes( []byte{72, 69, 76, 76, 79} )

asBytes  := parcel.Bytes()
asReader := parcel.Reader()
asRunes  := parcel.Runes()
asString := parcel.String()

n, err := parcel.WriteTo(writer)

Example #2a

import (
	"github.com/reiver/go-parcels"
)

// ...

parcel := parcels.ParcelFromString("This is some content!")

newParcel := parcel.Then(func(parcel Parcel)Parcel{
	s := strings.ToUpper(parcel.String)
	return parcels.ParcelFromString(s)
})

Example #2b

import (
	"github.com/reiver/go-parcels"
)

// ...

parcel := parcels.ParcelFromBytes( []byte{72, 69, 76, 76, 79} )

newParcel := parcel.Then(func(parcel Parcel)Parcel{
	s := strings.ToUpper(parcel.String)
	return parcels.ParcelFromString(s)
})

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Parcel

type Parcel interface {
	Bytes() []byte
	Reader() io.Reader
	Runes() []rune
	String() string
	WriteTo(w io.Writer) (int64, error)

	Then(func(Parcel) Parcel) Parcel
}

func ParcelFromBytes

func ParcelFromBytes(b []byte) Parcel

ParcelFromBytes returns a new Parcel whose contents is the value of the []byte. Note that the contents the input []byte 'b' is copied, and the new Parcel is not attached to the original backing memory.

Example

parcel := parcels.ParcelFromBytes( []byte{72, 69, 76, 76, 79} )

asBytes  := parcel.Bytes()
asReader := parcel.Reader()
asRunes  := parcel.Runes()
asString := parcel.String()

n, err := parcel.WriteTo(writer)

func ParcelFromRune

func ParcelFromRune(r rune) Parcel

ParcelFromRune returns a new Parcel whose contents is the value of the rune.

Example

parcel := parcels.ParcelFromRune('۵')

asBytes  := parcel.Bytes()
asReader := parcel.Reader()
asRunes  := parcel.Runes()
asString := parcel.String()

n, err := parcel.WriteTo(writer)

func ParcelFromString

func ParcelFromString(content string) Parcel

ParcelFromString returns a new Parcel whose contents is the value of the string.

Example

parcel := parcels.ParcelFromString("This is some text.")

asBytes  := parcel.Bytes()
asReader := parcel.Reader()
asRunes  := parcel.Runes()
asString := parcel.String()

n, err := parcel.WriteTo(writer)

Jump to

Keyboard shortcuts

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