You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by ma...@apache.org on 2015/10/31 23:22:28 UTC
[13/14] lucy git commit: Go bindings for CompoundFile[Reader/Writer].
Go bindings for CompoundFile[Reader/Writer].
Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/dd919892
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/dd919892
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/dd919892
Branch: refs/heads/master
Commit: dd919892767b7d6a09cae2844c4d456aa332fef4
Parents: a7f6c9f
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Tue Oct 27 20:11:33 2015 -0700
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Tue Oct 27 20:11:33 2015 -0700
----------------------------------------------------------------------
go/build.go | 4 ++++
go/lucy/store.go | 22 ++++++++++++++++++++++
go/lucy/store_test.go | 28 ++++++++++++++++++++++++++++
3 files changed, 54 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy/blob/dd919892/go/build.go
----------------------------------------------------------------------
diff --git a/go/build.go b/go/build.go
index 1d429ff..0691f6e 100644
--- a/go/build.go
+++ b/go/build.go
@@ -291,6 +291,10 @@ func specClasses(parcel *cfc.Parcel) {
lockBinding.SpecMethod("Release", "Release() error")
lockBinding.SpecMethod("Clear_Stale", "ClearStale() error")
lockBinding.Register()
+
+ cfWriterBinding := cfc.NewGoClass(parcel, "Lucy::Store::CompoundFileWriter")
+ cfWriterBinding.SpecMethod("Consolidate", "Consolidate() error")
+ cfWriterBinding.Register()
}
func build() {
http://git-wip-us.apache.org/repos/asf/lucy/blob/dd919892/go/lucy/store.go
----------------------------------------------------------------------
diff --git a/go/lucy/store.go b/go/lucy/store.go
index 05d6dc3..6fabd16 100644
--- a/go/lucy/store.go
+++ b/go/lucy/store.go
@@ -28,6 +28,8 @@ package lucy
#include "Lucy/Store/FileHandle.h"
#include "Lucy/Store/FSFileHandle.h"
#include "Lucy/Store/RAMFileHandle.h"
+#include "Lucy/Store/CompoundFileReader.h"
+#include "Lucy/Store/CompoundFileWriter.h"
#include "Clownfish/Err.h"
*/
@@ -697,3 +699,23 @@ func (lock *LockIMP) ClearStale() error {
C.LUCY_Lock_Clear_Stale(self)
})
}
+
+func OpenCompoundFileReader(folder Folder) (reader CompoundFileReader, err error) {
+ err = clownfish.TrapErr(func() {
+ folderC := (*C.lucy_Folder)(clownfish.Unwrap(folder, "Folder"))
+ cfObj := C.lucy_CFReader_open(folderC)
+ if cfObj == nil {
+ cfErr := C.cfish_Err_get_error();
+ panic(clownfish.WRAPAny(unsafe.Pointer(C.cfish_incref(unsafe.Pointer(cfErr)))).(error))
+ }
+ reader = WRAPCompoundFileReader(unsafe.Pointer(cfObj))
+ })
+ return reader, err
+}
+
+func (writer *CompoundFileWriterIMP) Consolidate() error {
+ return clownfish.TrapErr(func() {
+ self := (*C.lucy_CompoundFileWriter)(clownfish.Unwrap(writer, "writer"))
+ C.LUCY_CFWriter_Consolidate(self)
+ })
+}
http://git-wip-us.apache.org/repos/asf/lucy/blob/dd919892/go/lucy/store_test.go
----------------------------------------------------------------------
diff --git a/go/lucy/store_test.go b/go/lucy/store_test.go
index 29ed837..d4ef42b 100644
--- a/go/lucy/store_test.go
+++ b/go/lucy/store_test.go
@@ -698,3 +698,31 @@ func TestLockFactoryAll(t *testing.T) {
t.Errorf("MakeSharedLock")
}
}
+
+func TestCompoundFiles(t *testing.T) {
+ var err error
+ folder := NewRAMFolder("seg_6b")
+ out, _ := folder.OpenOut("foo")
+ out.WriteI32(42)
+ out.Close()
+
+ writer := NewCompoundFileWriter(folder)
+ err = writer.Consolidate()
+ if err != nil {
+ t.Errorf("Consolidate: %v", err)
+ }
+ err = writer.Consolidate()
+ if err == nil {
+ t.Errorf("Consolidating twice should fail")
+ }
+
+ reader, err := OpenCompoundFileReader(folder)
+ if err != nil {
+ t.Errorf("OpenCompoundFileReader: %v", err)
+ }
+ in, err := reader.OpenIn("foo")
+ if _, ok := in.(InStream); !ok || err != nil {
+ t.Errorf("Failed to open file within compound file: %v", err)
+ }
+ in.Close()
+}