Remove unnecessary C code and use everything from Golang

This commit is contained in:
Harshavardhana
2014-12-01 21:07:55 -08:00
parent 59c1197f47
commit 3a6cac8ada
5 changed files with 21 additions and 185 deletions

View File

@@ -19,11 +19,6 @@
package split
// #include <stdlib.h>
// #include <stdlib.h>
//
// #include "split.h"
import "C"
import (
"bufio"
"bytes"
@@ -32,38 +27,21 @@ import (
"io/ioutil"
"os"
"strconv"
"unsafe"
"github.com/minio-io/minio/pkgs/strbyteconv"
)
type Split struct {
bytecnt C.ssize_t
bname *C.char
}
func (b *Split) GenChunks(bname string, bytestr string) error {
bytecnt, err := strbyteconv.StringToBytes(bytestr)
if err != nil {
return err
}
b.bytecnt = C.ssize_t(bytecnt)
b.bname = C.CString(bname)
defer C.free(unsafe.Pointer(b.bname))
value := C.minio_split(b.bname, b.bytecnt)
if value < 0 {
return errors.New("File split failed")
}
return nil
}
type GoSplit struct {
file string
offset uint64
}
// Message structure for results from the SplitStream goroutine
type ByteMessage struct {
Data []byte
Err error
}
// SplitStream reads from io.Reader, splits the data into chunks, and sends
// each chunk to the channel. This method runs until an EOF or error occurs. If
// an error occurs, the method sends the error over the channel and returns.
@@ -117,20 +95,24 @@ func SplitStream(reader io.Reader, chunkSize uint64, ch chan ByteMessage) {
close(ch)
}
// Message structure for results from the SplitStream goroutine
type ByteMessage struct {
Data []byte
Err error
}
// Takes a file and splits it into chunks with size chunkSize. The output
// filename is given with outputPrefix.
func SplitFilesWithPrefix(filename string, chunkSize uint64, outputPrefix string) error {
func SplitFilesWithPrefix(filename string, chunkstr string, outputPrefix string) error {
// open file
file, err := os.Open(filename)
if err != nil {
return err
}
if outputPrefix == "" {
return errors.New("Invalid argument outputPrefix cannot be empty string")
}
chunkSize, err := strbyteconv.StringToBytes(chunkstr)
if err != nil {
return err
}
// start stream splitting goroutine
ch := make(chan ByteMessage)
go SplitStream(file, chunkSize, ch)