wip: archive
This commit is contained in:
parent
64e4ca400f
commit
7642caeb6b
@ -1 +1 @@
|
||||
golang 1.20.5
|
||||
golang 1.20.7
|
||||
|
||||
1
archive/dir.go
Normal file
1
archive/dir.go
Normal file
@ -0,0 +1 @@
|
||||
package archive
|
||||
@ -3,8 +3,9 @@ package spt
|
||||
import (
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"gitea.suyono.dev/suyono/simple-privacy-tool/privacy"
|
||||
"io"
|
||||
|
||||
"gitea.suyono.dev/suyono/simple-privacy-tool/privacy"
|
||||
)
|
||||
|
||||
type decryptApp struct {
|
||||
@ -32,9 +33,9 @@ func (d *decryptApp) ProcessFiles() (err error) {
|
||||
)
|
||||
|
||||
if f.IsBase64() {
|
||||
src = base64.NewDecoder(base64.StdEncoding, d.srcFile)
|
||||
src = base64.NewDecoder(base64.StdEncoding, d.src)
|
||||
} else {
|
||||
src = d.srcFile
|
||||
src = d.src
|
||||
}
|
||||
|
||||
d.r = privacy.NewPrivacyReaderWithKeyGen(src, f.KeyGen())
|
||||
@ -53,15 +54,15 @@ redo:
|
||||
return
|
||||
}
|
||||
|
||||
if _, err = io.Copy(d.dstFile, d.r); err != nil {
|
||||
if _, err = io.Copy(d.dst, d.r); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if err = d.dstFile.Close(); err != nil {
|
||||
if err = d.dst.Close(); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if err = d.srcFile.Close(); err != nil {
|
||||
if err = d.src.Close(); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@ -2,8 +2,9 @@ package spt
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"gitea.suyono.dev/suyono/simple-privacy-tool/privacy"
|
||||
"io"
|
||||
|
||||
"gitea.suyono.dev/suyono/simple-privacy-tool/privacy"
|
||||
)
|
||||
|
||||
type encryptApp struct {
|
||||
@ -38,9 +39,9 @@ func (e *encryptApp) ProcessFiles() (err error) {
|
||||
var dst io.WriteCloser
|
||||
|
||||
if f.IsBase64() {
|
||||
dst = base64.NewEncoder(base64.StdEncoding, e.dstFile)
|
||||
dst = base64.NewEncoder(base64.StdEncoding, e.dst)
|
||||
} else {
|
||||
dst = e.dstFile
|
||||
dst = e.dst
|
||||
}
|
||||
|
||||
if f.IncludeHint() {
|
||||
@ -58,7 +59,7 @@ func (e *encryptApp) ProcessFiles() (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
if _, err = io.Copy(e.wc, e.srcFile); err != nil {
|
||||
if _, err = io.Copy(e.wc, e.src); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
@ -66,7 +67,7 @@ func (e *encryptApp) ProcessFiles() (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
if err = e.srcFile.Close(); err != nil {
|
||||
if err = e.src.Close(); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@ -2,19 +2,21 @@ package spt
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"io"
|
||||
"os"
|
||||
|
||||
"log"
|
||||
|
||||
tw "gitea.suyono.dev/suyono/terminal_wrapper"
|
||||
"github.com/spf13/cobra"
|
||||
"log"
|
||||
)
|
||||
|
||||
type cApp struct {
|
||||
term *tw.Terminal
|
||||
srcPath string
|
||||
dstPath string
|
||||
srcFile *os.File
|
||||
dstFile *os.File
|
||||
src io.ReadCloser
|
||||
dst io.WriteCloser
|
||||
passphrase string
|
||||
}
|
||||
|
||||
@ -163,23 +165,23 @@ func decrypt(cmd *cobra.Command, args []string) (err error) {
|
||||
|
||||
func (a *cApp) ProcessArgs(args []string) (err error) {
|
||||
if len(args) == 0 {
|
||||
a.srcFile = os.Stdin
|
||||
a.dstFile = os.Stdout
|
||||
a.src = os.Stdin
|
||||
a.dst = os.Stdout
|
||||
} else {
|
||||
a.srcPath = args[0]
|
||||
a.dstPath = args[1]
|
||||
if a.srcPath == "-" {
|
||||
a.srcFile = os.Stdin
|
||||
a.src = os.Stdin
|
||||
} else {
|
||||
if a.srcFile, err = os.Open(a.srcPath); err != nil {
|
||||
if a.src, err = os.Open(a.srcPath); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if a.dstPath == "-" {
|
||||
a.dstFile = os.Stdout
|
||||
a.dst = os.Stdout
|
||||
} else {
|
||||
if a.dstFile, err = os.OpenFile(a.dstPath, os.O_CREATE|os.O_WRONLY, 0640); err != nil { //TODO: allow user to define the destination file permission
|
||||
if a.dst, err = os.OpenFile(a.dstPath, os.O_CREATE|os.O_WRONLY, 0640); err != nil { //TODO: allow user to define the destination file permission
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user