Example #1
0
func main() {
	if len(os.Args) < 3 {
		fmt.Println("Input format : test input output")
		return
	}
	filestr := os.Args[1]
	fileoutstr := os.Args[2]
	file, err := os.Open(filestr)
	defer file.Close()
	if err != nil {
		panic(err)
	}
	ofile, err := os.Create(fileoutstr)
	if err != nil {
		panic(err)
	}
	defer ofile.Close()
	r := client.NewIdxReader(file)
	/*for {
		b := make([]byte,1024,1024)
		_,err := r.Read(b)
		if err == io.EOF{
			break
		}else if err != nil{
			panic(err)
		}
		fmt.Printf("%x\n",b)
	}
	return*/
	_, err = io.Copy(ofile, r)
	if err != nil {
		panic(err)
	}
}
Example #2
0
func postHash(url string, file string) {
	f, err := os.Open(file)
	if err != nil {
		panic(err)
	}
	defer f.Close()
	b := client.NewIdxReader(f)
	req, err := http.NewRequest("POST", url, b)
	if err != nil {
		panic(err)
	}
	client := &http.Client{}
	fmt.Println("debug ")
	res, err := client.Do(req)
	if err != nil {
		panic(err)
	}
	if res.StatusCode != http.StatusOK {
		err = fmt.Errorf("bad status:%s", res.Status)
		return
	}
	body, err := ioutil.ReadAll(res.Body)
	if err != nil {
		panic(err)
	}
	fmt.Println(string(body))
}