Created
July 26, 2023 16:02
-
-
Save miknonny/ea3994fdf02659cbff634491e6ecc08a to your computer and use it in GitHub Desktop.
read fixed byte size from http connection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"flag" | |
"fmt" | |
"log" | |
"net/http" | |
"os" | |
) | |
func main() { | |
filename := flag.String("name", "", "please provide a file name") | |
flag.Parse() | |
if *filename == "" { | |
log.Fatal("failed to provide a filename") | |
} | |
file, err := os.Open(*filename) | |
if err != nil { | |
log.Fatal(err) | |
} | |
bufferSize := 930 | |
buffer := make([]byte, bufferSize) | |
n, err := file.Read(buffer) | |
if err != nil { | |
log.Fatal(err) | |
} | |
fmt.Println(buffer) | |
mimeType := http.DetectContentType(buffer[:n]) | |
fmt.Println(mimeType) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment