cocoa

package module
v0.0.0-...-82a0d65 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2018 License: Apache-2.0 Imports: 12 Imported by: 3

README

GoDoc

Cocoa

Pure Go reimplementation of some Cocoa specific features.

Work in progress, this code is NOT production ready. There is a hight risk that it will erase all your data and might also make your pets sick!

Alias

Cocoa has a concept of alias which work a little bit like hard links but with more flexibility. Unfortunately this feature isn't exposed outside of Cocoa and while we could use cgo to generate a aliases, a pure Go solution has its advantages. This implementation is based on many guesses and can be seen as a hack. Use at your own risks.

if err := cocoa.Alias("source/path", "destination/path"); err != nil {
    panic(err)
}

Similar to the following Swift code:

import Foundation

var originalUrl = NSURL.fileURL(withPath: "source/path")
var aliasUrl = NSURL.fileURL(withPath: "destination/path")
var bookmarkData = try? originalUrl.bookmarkData(options: NSURL.BookmarkCreationOptions.suitableForBookmarkFile,
                                                 includingResourceValuesForKeys: nil, relativeTo: nil)
// URLBookmarkCreationSuitableForBookmarkFile
try? URL.writeBookmarkData(bookmarkData!, to: aliasUrl)

Check GoDoc for more information.

Documentation

Overview

The cocoa package reimplements some native Cocoa features in pure Go so Go programs running on Mac don't need to call into Cocoa. The goal of this project is not to replace or cover all Cocoa APIs but to facilitate the work of Gophers on Mac.

Index

Constants

View Source
const (
	AliasKindFile   = 0
	AliasKindFolder = 1
)
View Source
const (

	// Bookmark keys
	//                           = 0x1003
	KBookmarkPath           = 0x1004 // Array of path components
	KBookmarkCNIDPath       = 0x1005 // Array of CNIDs
	KBookmarkFileProperties = 0x1010 // (CFURL rp flags,
	//  CFURL rp flags asked for,
	//  8 bytes NULL)
	KBookmarkFileName         = 0x1020
	KBookmarkFileID           = 0x1030
	KBookmarkFileCreationDate = 0x1040
	KBookmarkUnknown          = 0x1054 // always 1?
	KBookmarkUnknown1         = 0x1055 // point to value in 0x1054
	KBookmarkUnknown2         = 0x1056 // boolean, always true?

	//                           = 0x1101   // ?
	//                           = 0x1102   // ?
	KBookmarkTOCPath            = 0x2000 // A list of (TOC id, ?) pairs
	KBookmarkVolumePath         = 0x2002
	KBookmarkVolumeURL          = 0x2005
	KBookmarkVolumeName         = 0x2010
	KBookmarkVolumeUUID         = 0x2011 // Stored (perversely) as a string
	KBookmarkVolumeSize         = 0x2012
	KBookmarkVolumeCreationDate = 0x2013
	KBookmarkVolumeProperties   = 0x2020
	KBookmarkVolumeIsRoot       = 0x2030 // True if volume is FS root
	KBookmarkVolumeBookmark     = 0x2040 // Embedded bookmark for disk image (TOC id)
	KBookmarkVolumeMountPoint   = 0x2050 // A URL
	//                           = 0x2070
	KBookmarkContainingFolder  = 0xc001 // Index of containing folder in path
	KBookmarkUserName          = 0xc011 // User that created bookmark
	KBookmarkUID               = 0xc012 // UID that created bookmark
	KBookmarkWasFileReference  = 0xd001 // True if the URL was a file reference
	KBookmarkCreationOptions   = 0xd010
	KBookmarkURLLengths        = 0xe003 // See below
	KBookmarkFullFileName      = 0xf017
	KBookmarkFileType          = 0xf022 // -> 0x201 looks like some file reference with file extension
	KBookmarkSecurityExtension = 0xf080
)

bookmarks flags

Variables

View Source
var (
	Debug bool
)

Functions

func Alias

func Alias(src, dst string) error

Alias acts like os.Symlink but instead of creating a symlink, a bookmark is stored.

func IsAlias

func IsAlias(src string) bool

IsAlias returns positively if the passed file path is an alias.

Types

type AliasRecord

type AliasRecord struct {
	Path      string
	CNIDPath  []uint32
	PathItems []string
	// Application specific four-character code
	AppCode [4]byte
	// Version (only 2 is supported)
	Version uint16
	// Alias kind (0 = file, 1 = folder)
	Kind uint16
	// Volume name (encoded as Pascal style)
	VolumeName string
	// Volume date (encoded as seconds since 1904-01-01 00:00:00 UTC)
	VolumeDate time.Time
	// Filesystem type (typically ‘H+’ for HFS+)
	FileSystem string
	// Disk type (0 = fixed, 1 = network, 2 = 400Kb, 3 = 800kb, 4 = 1.44MB, 5 = ejectable)
	DiskType uint16
	// CNID of containing folder
	FolderCNID uint32
	// Target name (encoded as Pascal-style string)
	TargetName string
	// Target CNID
	TargetCNID uint32
	// Target creation date (encoded as seconds since 1904-01-01 00:00:00 UTC)
	TargetCreation time.Time
	// Target creator code (four-character code)
	TargetCreator [4]byte
	// Target type code (four-character code)
	TargetType [4]byte
	// Number of directory levels from alias to root (or -1)
	DirsAliasToRoot int16
	// Number of directory levels from root to target (or -1)
	DirsRootToTarget int16
	// Volume attributes
	VolumeAttributes [4]byte
	// Volume filesystem ID
	VolumeID uint16
}

AliasRecord is an alias representation that can be shared in memory For file persistency, see the Alias with bookmark data.

func NewAliasRecord

func NewAliasRecord(path string) (*AliasRecord, error)

func (*AliasRecord) Encode

func (a *AliasRecord) Encode() ([]byte, error)

Encode converts the AliasRecord into binary data and returns the byte data

type BookmarkData

type BookmarkData struct {
	FileSystemType string
	Path           []string
	// CNIDPath in the case of an alias file is the offset to the path element (minus header size)
	CNIDPath            []uint64
	FileCreationDate    time.Time
	FileProperties      []byte
	TypeData            []byte // from 0xf022
	ContainingFolderIDX uint32
	VolumePath          string
	VolumeIsRoot        bool
	VolumeURL           string // file://' + volPath
	VolumeName          string
	VolumeSize          int64
	VolumeCreationDate  time.Time
	VolumeUUID          string // must be uppercase
	VolumeProperties    []byte
	CreationOptions     uint32 // 512
	WasFileReference    bool   // true
	UserName            string // unknown
	CNID                uint32
	UID                 uint32 // 99
	Filename            string
}

BookmarkData represents the data structure holding the bookmark information

func AliasFromReader

func AliasFromReader(r io.Reader) (*BookmarkData, error)

AliasFromReader takes an io.reader pointing to an alias file decodes it and returns the contained bookmark data.

func (*BookmarkData) String

func (b *BookmarkData) String() string

func (*BookmarkData) TargetPath

func (b *BookmarkData) TargetPath() string

TargetPath returns the full path to the current target url.

func (*BookmarkData) Write

func (b *BookmarkData) Write(w io.Writer) error

Write converts the bookmark data into binary data and writes it to the passed writer. Note that the writes are buffered and written all at once.

Directories

Path Synopsis
cmd
daring is a package implementing low level features exposed in Cocoa but that can also be used directly in pure Go via syscalls.
daring is a package implementing low level features exposed in Cocoa but that can also be used directly in pure Go via syscalls.

Jump to

Keyboard shortcuts

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