diff --git a/utilities/export.go b/utilities/export.go index 48efd256..24af5ec4 100644 --- a/utilities/export.go +++ b/utilities/export.go @@ -2,7 +2,7 @@ package utilities import ( "bytes" - + "encoding/base64" "github.com/ahmdrz/goinsta" ) @@ -14,3 +14,14 @@ func ExportAsBytes(insta *goinsta.Instagram) ([]byte, error) { } return buffer.Bytes(), nil } + +// ExportAsBase64String exports selected *Instagram object as base64 encoded string +func ExportAsBase64String(insta *goinsta.Instagram) (string, error) { + bytes, err := ExportAsBytes(insta) + if err != nil { + return "", err + } + + sEnc := base64.StdEncoding.EncodeToString(bytes) + return sEnc, nil +} diff --git a/utilities/import.go b/utilities/import.go index 4a69cce9..7894c6f8 100644 --- a/utilities/import.go +++ b/utilities/import.go @@ -2,10 +2,22 @@ package utilities import ( "bytes" - + "encoding/base64" "github.com/ahmdrz/goinsta" ) func ImportFromBytes(inputBytes []byte) (*goinsta.Instagram, error) { return goinsta.ImportReader(bytes.NewReader(inputBytes)) } + +// ImportFromBase64String imports instagram configuration from a base64 encoded string. +// +// This function does not set proxy automatically. Use SetProxy after this call. +func ImportFromBase64String(base64String string) (*goinsta.Instagram, error) { + sDec, err := base64.StdEncoding.DecodeString(base64String) + if err != nil { + return nil, err + } + + return ImportFromBytes(sDec) +}