Example #1
0
func convert(r *http.Request, format string) ([]byte, error) {
	upload, _, err := r.FormFile("file")

	if err != nil {
		return nil, err
	}

	defer upload.Close()

	in_file, err := ioutil.TempFile(os.TempDir(), "")
	defer os.Remove(in_file.Name())

	if _, err = io.Copy(in_file, upload); nil != err {
		return nil, err
	}

	doc := C.documentLoad(lo, C.CString(in_file.Name()))

	if doc == nil {
		return nil, errors.New("documentLoad failed")
	}

	out_file, err := ioutil.TempFile(os.TempDir(), "")
	defer os.Remove(out_file.Name())

	C.saveAs(doc, C.CString(out_file.Name()), C.CString(format))
	C.destroy(doc)

	bytes, err := ioutil.ReadFile(out_file.Name())

	if err != nil {
		return nil, err
	}

	return bytes, nil
}
Example #2
0
// Close destroys radix tree.
func (rtree *NetRadixTree) Close() {
	C.destroy(rtree.tree)
}