Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions ios/nskeyedarchiver/archiverutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"encoding/json"
"fmt"
"io"

plist "howett.net/plist"
)
Expand All @@ -26,16 +27,13 @@ func toUidList(list []interface{}) []plist.UID {
return result
}

// plistFromBytes decodes a binary or XML based PLIST using the amazing github.com/DHowett/go-plist library and returns an interface{} or propagates the error raised by the library.
func plistFromBytes(plistBytes []byte) (interface{}, error) {
var test interface{}
decoder := plist.NewDecoder(bytes.NewReader(plistBytes))
// plistFromReader decodes a binary or XML based PLIST using the amazing github.com/DHowett/go-plist library and returns an interface{} or propagates the error raised by the library.
func plistFromReader(r io.ReadSeeker) (interface{}, error) {
var v interface{}
decoder := plist.NewDecoder(r)

err := decoder.Decode(&test)
if err != nil {
return test, err
}
return test, nil
err := decoder.Decode(&v)
return v, err
}

// ToPlist converts a given struct to a Plist using the
Expand Down
12 changes: 11 additions & 1 deletion ios/nskeyedarchiver/unarchiver.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package nskeyedarchiver

import (
"bytes"
"fmt"
"io"
"runtime/debug"

log "github.com/sirupsen/logrus"
Expand All @@ -13,6 +15,14 @@ import (
// 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.
func Unarchive(xml []byte) (result []interface{}, err error) {
return UnarchiveReader(bytes.NewReader(xml))
}

// UnarchiveReader extracts NSKeyedArchiver Plists from an io.ReadSeeker, 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 be transformed into []interface{}.
// NSDictionary and NSMutableDictionary will be transformed into map[string]interface{}. Non-string keys might be added later.
func UnarchiveReader(r io.ReadSeeker) (result []interface{}, err error) {
defer func() {
if r := recover(); r != nil {
stacktrace := string(debug.Stack())
Expand All @@ -21,7 +31,7 @@ func Unarchive(xml []byte) (result []interface{}, err error) {
}()

SetupDecoders()
plist, err := plistFromBytes(xml)
plist, err := plistFromReader(r)
if err != nil {
return nil, err
}
Expand Down