Skip to content
This repository has been archived by the owner on Aug 25, 2023. It is now read-only.

Commit

Permalink
added export and import as base64 string function (#242)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderProd authored and ahmdrz committed Jun 1, 2019
1 parent c9af8ed commit 346af49
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
13 changes: 12 additions & 1 deletion utilities/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package utilities

import (
"bytes"

"encoding/base64"
"github.com/ahmdrz/goinsta"
)

Expand All @@ -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
}
14 changes: 13 additions & 1 deletion utilities/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit 346af49

Please sign in to comment.