In the first quarter of 2018, the demand for blockchain-related talent had reached 9.7 times times the same period in 2017, with a 4.6 times-fold increase in the number of companies publishing blockchain-related posts.
Brother Lian Education go all-in-one and Blockchain training courses are unique, structured courses developed by Tsinghua, Microsoft, and Google teachers over the course of a half-year period.
Compress files
Package Main
Import (
"FMT"
"OS"
"IO"
"Archive/tar"
"Compress/gzip"
)
Func Main () {
File Write
FW, ERR: = OS. Create ("tar/lin_golang_src.tar.gz")
If err! = Nil {
Panic (ERR)
}
Defer FW. Close ()
Gzip Write
GW: = gzip. Newwriter (FW)
Defer GW. Close ()
Tar Write
TW: = tar. Newwriter (GW)
Defer TW. Close ()
Open Folder
Dir, err: = OS. Open ("file/")
If err! = Nil {
Panic (Nil)
}
Defer dir. Close ()
Read a list of files
FIS, err: = dir. Readdir (0)
If err! = Nil {
Panic (ERR)
}
Traverse file List
For _, Fi: = Range fis {
Escape the folder, I will not be recursive here
If Fi. Isdir () {
Continue
}
Print file name
Fmt. Println (FI. Name ())
Open File
FR, err: = OS. Open (dir. Name () + "/" + FI. Name ())
If err! = Nil {
Panic (ERR)
}
Defer Fr. Close ()
Information header
H: = new (tar. Header)
H.name = fi. Name ()
H.size = fi. Size ()
H.mode = Int64 (FI. Mode ())
H.modtime = fi. Modtime ()
Write message header
Err = tw. Writeheader (h)
If err! = Nil {
Panic (ERR)
}
Write a file
_, err = Io. Copy (TW, FR)
If err! = Nil {
Panic (ERR)
}
}
Fmt. Println ("tar.gz OK")
}
Unzip the file
Package Main
Import (
"FMT"
"OS"
"IO"
"Time"
"Archive/tar"
"Compress/gzip"
)
Func Main () {
File read
FR, err: = OS. Open ("tar/lin_golang_src.tar.gz")
If err! = Nil {
Panic (ERR)
}
Defer Fr. Close ()
Gzip Read
GR, err: = gzip. Newreader (FR)
If err! = Nil {
Panic (ERR)
}
Defer Gr. Close ()
Tar read
TR: = tar. Newreader (GR)
Read file
for {
H, err: = tr. Next ()
If err = = Io. EOF {
Break
}
If err! = Nil {
Panic (ERR)
}
Show Files
Fmt. Println (H.name)
Open File
FW, ERR: = OS. OpenFile ("file2/" + h.name, os. O_create | Os. O_wronly, 0644/*os. FileMode (H.mode) */)
If err! = Nil {
Panic (ERR)
}
Defer FW. Close ()
Write a file
_, err = Io. Copy (FW, TR)
If err! = Nil {
Panic (ERR)
}
}
Fmt. Println ("Un tar.gz OK")
}