This is an automated email from the git hooks/post-receive script.
git pushed a commit to branch main
in repository ego.
View the commit online.
commit c1c67243734d7fd6e90a622b26feeb78b9eb9932
Author: [email protected] <[email protected]>
AuthorDate: Thu Mar 26 21:24:53 2026 -0600
feat(eet): add File type with Open, Create, OpenFile, Close, Sync, WriteRaw
Introduces the File type wrapping Eet_File* to provide a Go-idiomatic
interface for EET file operations. Implements core file lifecycle methods:
- Open: opens existing files for reading
- Create: creates new files for writing
- OpenFile: flexible mode-based file opening
- Close: closes files with EET_ERROR_EMPTY treated as success (empty file
is not an error condition)
- Sync: flushes pending writes
- WriteRaw: raw byte storage using eet_write_cipher
Includes comprehensive test coverage for Create/Open round-trip,
non-existent file error handling, and ReadWrite mode support.
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
---
eet/eet_test.go | 54 +++++++++++++++++++++++++++++++++++++
eet/file.go | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 137 insertions(+)
diff --git a/eet/eet_test.go b/eet/eet_test.go
new file mode 100644
index 0000000..f478a0f
--- /dev/null
+++ b/eet/eet_test.go
@@ -0,0 +1,54 @@
+package eet_test
+
+import (
+ "path/filepath"
+ "testing"
+
+ "git.enlightenment.org/cedric/ego/eet"
+)
+
+func TestCreateAndOpen(t *testing.T) {
+ dir := t.TempDir()
+ path := filepath.Join(dir, "test.eet")
+
+ f, err := eet.Create(path)
+ if err != nil {
+ t.Fatalf("Create: %v", err)
+ }
+ // EET requires at least one entry to produce a valid on-disk file.
+ // An empty write-mode file is not re-openable with ModeRead.
+ if _, err := f.WriteRaw("seed", []byte("ok"), eet.CompressNone); err != nil {
+ t.Fatalf("WriteRaw: %v", err)
+ }
+ if err := f.Close(); err != nil {
+ t.Fatalf("Close after Create: %v", err)
+ }
+
+ f, err = eet.Open(path)
+ if err != nil {
+ t.Fatalf("Open: %v", err)
+ }
+ if err := f.Close(); err != nil {
+ t.Fatalf("Close after Open: %v", err)
+ }
+}
+
+func TestOpenNonExistent(t *testing.T) {
+ _, err := eet.Open("/tmp/eet_test_nonexistent_file.eet")
+ if err == nil {
+ t.Fatal("expected error opening non-existent file")
+ }
+}
+
+func TestOpenFileReadWrite(t *testing.T) {
+ dir := t.TempDir()
+ path := filepath.Join(dir, "rw.eet")
+
+ f, err := eet.OpenFile(path, eet.ModeReadWrite)
+ if err != nil {
+ t.Fatalf("OpenFile: %v", err)
+ }
+ if err := f.Close(); err != nil {
+ t.Fatalf("Close: %v", err)
+ }
+}
diff --git a/eet/file.go b/eet/file.go
new file mode 100644
index 0000000..a1de134
--- /dev/null
+++ b/eet/file.go
@@ -0,0 +1,83 @@
+package eet
+
+/*
+#include <Eet.h>
+#include <stdlib.h>
+*/
+import "C"
+import "unsafe"
+
+// File wraps an Eet_File handle.
+type File struct {
+ ptr *C.Eet_File
+}
+
+// Open opens an existing EET file for reading.
+func Open(path string) (*File, error) {
+ return OpenFile(path, ModeRead)
+}
+
+// Create creates or truncates an EET file for writing.
+func Create(path string) (*File, error) {
+ return OpenFile(path, ModeWrite)
+}
+
+// OpenFile opens an EET file with the specified mode.
+func OpenFile(path string, mode Mode) (*File, error) {
+ cPath := C.CString(path)
+ defer C.free(unsafe.Pointer(cPath))
+
+ cMode := C.Eet_File_Mode(mode)
+ ef := C.eet_open(cPath, cMode)
+ if ef == nil {
+ return nil, ErrBadFile
+ }
+ return &File{ptr: ef}, nil
+}
+
+// Close closes the EET file and flushes any pending writes.
+// EET_ERROR_EMPTY is treated as success: it indicates an empty file was
+// closed without any writes, which is not an application error.
+func (f *File) Close() error {
+ if f.ptr == nil {
+ return nil
+ }
+ errCode := C.eet_close(f.ptr)
+ f.ptr = nil
+ if errCode != C.EET_ERROR_NONE && errCode != C.EET_ERROR_EMPTY {
+ return ErrBadFile
+ }
+ return nil
+}
+
+// WriteRaw writes raw bytes under the given key with optional compression.
+// It returns the number of bytes stored, or an error.
+func (f *File) WriteRaw(key string, data []byte, compress Compression) (int, error) {
+ if f.ptr == nil {
+ return 0, ErrBadFile
+ }
+ cKey := C.CString(key)
+ defer C.free(unsafe.Pointer(cKey))
+
+ var ptr unsafe.Pointer
+ if len(data) > 0 {
+ ptr = unsafe.Pointer(&data[0])
+ }
+ n := C.eet_write_cipher(f.ptr, cKey, ptr, C.int(len(data)), C.int(compress), nil)
+ if n == 0 {
+ return 0, ErrEncode
+ }
+ return int(n), nil
+}
+
+// Sync flushes any pending writes to the underlying file.
+func (f *File) Sync() error {
+ if f.ptr == nil {
+ return ErrBadFile
+ }
+ ret := C.eet_sync(f.ptr)
+ if ret != C.EET_ERROR_NONE {
+ return ErrBadFile
+ }
+ return nil
+}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.