// ChunkEnd starts from the end of the chunk and increments
// until it finds a newline and returns that position.
// If it encounters EOF before a new line, it returns -1.
func ChunkEnd(f *os.File, start int64) int64 {
	nl := byte('\n')
	buf := make([]byte, 1)
	curpos := start
	fmt.Println("ChunkeEnd start=", start)

	readseek := io.ReadSeeker(f)
	offset, err := readseek.Seek(start, 0)
	if err != nil {
		log.Fatalf(fmt.Sprintf("FindString: error on seek-%n\n", err))
		os.Exit(1)
	}
	if offset != start {
		log.Fatalf("Expected offset of %d and received %d\n", start, offset)
	}
	reader := io.ReaderAt(f)

	for {
		nr, _ := reader.ReadAt(buf, curpos)
		//fmt.Printf("curpos=%d nr=%d buf=%s\n", curpos, nr, buf)
		curpos++
		if nr == 0 || buf[0] == nl { // EOF or neline
			break
		}
	}
	return int64(curpos)
}
// ChunkEnd starts from the end of the chunk and increments
// until it finds a newline and returns that position.
// If it encounters EOF before a new line, it returns -1.
func ChunkEnd(f *os.File, start int64) int64 {
	nl := byte('\n')
	buf := make([]byte, 1)
	curpos := start

	readseek := io.ReadSeeker(f)
	offset, err := readseek.Seek(start, 0)
	if err != nil {
		log.Fatalf(fmt.Sprintf("FindString: error on seek-%v\n", err))
		os.Exit(1)
	}
	if offset != start {
		log.Fatalf("Expected offset of %d and received %d\n", start, offset)
	}
	reader := io.ReaderAt(f)

	for {
		nr, _ := reader.ReadAt(buf, curpos)
		if nr == 0 { // EOF
			break
		}
		if buf[0] == nl {
			break
		} else {
			curpos++
		}
	}
	return int64(curpos)
}
Beispiel #3
0
// Some assertions around filehandle's applicability
func TestTypes(t *testing.T) {
	_ = os.FileInfo(&FileHandle{})
	_ = io.Closer(&FileHandle{})
	_ = io.Reader(&FileHandle{})
	_ = io.ReaderAt(&FileHandle{})
	_ = io.WriterTo(&FileHandle{})
	_ = io.Seeker(&FileHandle{})
}
Beispiel #4
0
import "C"

import (
	"fmt"
	"io"
	"unsafe"

	"gopkg.in/errgo.v1"
)

const useLobRead2 = true

// Compile-time guarantees for interface implementations.
var _ = io.Writer(&ExternalLobVar{})
var _ = io.Reader(&ExternalLobVar{})
var _ = io.ReaderAt(&ExternalLobVar{})
var _ = io.WriterAt(&ExternalLobVar{})

// Defines the routines for handling LOB variables external to this module.

// ExternalLobVar is an external LOB var type.
// It is NOT concurrent-safe ATM.
type ExternalLobVar struct {
	lobVar           *Variable
	idx              uint
	internalFetchNum uint
	isFile           bool
	rwPos            int64
}

func (lv ExternalLobVar) getHandle() *C.OCILobLocator {
Beispiel #5
0
			}
			n += int64(k)
			if lr.off == lr.Length {
				break
			}
		}
		if lr.piece == C.OCI_FIRST_PIECE {
			lr.piece = C.OCI_NEXT_PIECE
		}
	}
	return n, nil
}

// TODO(tgulacsi): find how to return lobReadWriter.

var _ = io.ReaderAt((*lobReadWriter)(nil))
var _ = io.WriterAt((*lobReadWriter)(nil))

type lobReadWriter struct {
	ses           *Ses
	ociLobLocator *C.OCILobLocator
	charsetForm   C.ub1
	size          C.oraub8
}

// Size returns the actual size of the LOB.
func (lrw lobReadWriter) Size() uint64 {
	return uint64(lrw.size)
}

// Close the LOB.