mirror of
https://github.com/schollz/croc.git
synced 2025-10-11 13:21:00 +02:00
Automatically compress directory to tar.gz archive
This commit is contained in:
parent
17d7b76f08
commit
0040f7161d
1 changed files with 31 additions and 4 deletions
27
connect.go
27
connect.go
|
@ -4,6 +4,7 @@ import (
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/verybluebot/tarinator-go"
|
||||||
"io"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
|
@ -37,6 +38,7 @@ type FileMetaData struct {
|
||||||
Size int
|
Size int
|
||||||
Hash string
|
Hash string
|
||||||
Path string
|
Path string
|
||||||
|
isDir bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewConnection(flags *Flags) *Connection {
|
func NewConnection(flags *Flags) *Connection {
|
||||||
|
@ -49,6 +51,31 @@ func NewConnection(flags *Flags) *Connection {
|
||||||
c.NumberOfConnections = flags.NumberOfConnections
|
c.NumberOfConnections = flags.NumberOfConnections
|
||||||
c.rate = flags.Rate
|
c.rate = flags.Rate
|
||||||
if len(flags.File) > 0 {
|
if len(flags.File) > 0 {
|
||||||
|
// check wether the file is a dir
|
||||||
|
info, err := os.Stat(flags.File)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("Error! Please submit the following error to https://github.com/schollz/croc/issues:\n\n'%s'\n\n", err.Error())
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
if info.Mode().IsDir() { // if our file is a dir
|
||||||
|
fmt.Print("The file you are trying to send is a directory; compressing...")
|
||||||
|
|
||||||
|
tmpFileName := "to_send.tmp.tar.gz"
|
||||||
|
// we "tarify" the file
|
||||||
|
err = tarinator.Tarinate([]string{flags.File}, tmpFileName)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("Error! Please submit the following error to https://github.com/schollz/croc/issues:\n\n'%s'\n\n", err.Error())
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
// now, we change the target file name to match the new archive created
|
||||||
|
flags.File = tmpFileName
|
||||||
|
// we set the value isDir to true
|
||||||
|
c.File.isDir = true
|
||||||
|
fmt.Println("Done !")
|
||||||
|
}
|
||||||
|
|
||||||
c.File.Name = path.Base(flags.File)
|
c.File.Name = path.Base(flags.File)
|
||||||
c.File.Path = path.Dir(flags.File)
|
c.File.Path = path.Dir(flags.File)
|
||||||
c.IsSender = true
|
c.IsSender = true
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue