nskeyedarchiver

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

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

Go to latest
Published: Apr 12, 2023 License: MIT Imports: 8 Imported by: 0

README

nskeyedarchiver

A fork extending @danielpaulus's excellent Golang based implementation NSKeyedArchiver with support for extracting Time, String, and custom objects.

Unarchive extracts NSKeyedArchiver Plists, either in XML or Binary format, and returns an array of the archived objects converted to usable Go Types.

  • Primitives will be extracted just like regular Plist primitives (string, float64, int64, []uint8 etc.).
  • NSArray, NSMutableArray, NSSet and NSMutableSet will transformed into []interface{}
  • NSDictionary and NSMutableDictionary will be transformed into map[string] interface{}. I might add non string keys later.

Todos:

  • Add custom object support (anything that is not an array, set or dictionary)
  • Add archiving/encoding support

Unarchive example:

package main

import (
	"fmt"
	"io/ioutil"

	"github.com/qcasey/nskeyedarchiver"
)

func main() {
	fileData, err := ioutil.ReadFile("apple-nskeyedariver.plist")
	if err != nil {
		fmt.Println("File reading error", err)
		return
	}

	plistData, err := nskeyedarchiver.Unarchive(fileData)
	if err != nil {
		fmt.Println("Error decoding plist:", err)
		return
	}
	
	for key, value := range plistData[0].(map[string]interface{}) {
		fmt.Printf("%s = %v (%T)\n", key, value, value)
	}
}

Thanks howett.net/plist for your awesome Plist library :-)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NSDateToTime

func NSDateToTime(timestamp float64) (time.Time, error)

NSDateToTime takes an Apple Cocoa Core Data timestamp and returns a golang time https://www.epochconverter.com/coredata

func ToPlist

func ToPlist(data interface{}) string

ToPlist returns a string containing the plist.

func Unarchive

func Unarchive(xml []byte) ([]interface{}, error)

Unarchive extracts NSKeyedArchiver Plist`s, either in XML or Binary format, and returns an array of the archived objects converted to usable Go Types. Primitives will be extracted just like regular Plist primitives (string, float64, int64, []uint8 etc.). NSArray, NSMutableArray, NSSet and NSMutableSet will transformed into []interface{} NSDictionary and NSMutableDictionary will be transformed into map[string] interface{}. I might add non string keys later.

Types

This section is empty.

Jump to

Keyboard shortcuts

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