Commits

Markus Tzoe  committed 51290c6

add String()

  • Participants
  • Parent commits 2cec549

Comments (0)

Files changed (1)

     entry  []dBaseRecord
 }
 
-type dbReader *dBaseFile
-type dbWriter *dBaseFile
+type dbReader dBaseFile
+type dbWriter dBaseFile
 
-func NewReader(path string) (ret *dBaseFile, err error) {
-    ret = new(dBaseFile)
+func NewDBReader(path string) (ret *dbReader, err error) {
+    ret = new(dbReader)
     ret.base, err = ioutil.ReadFile(path)
     if err != nil {
         return nil, err
     return ret, nil
 }
 
-func (f *dBaseFile) verify() (bool, error) {
+func NewDBWriter(path string) (writer *dbWriter, err error) {
+    writer = new(dbWriter)
+    return writer, nil
+}
+
+func (w *dbWriter) Flush() {
+
+}
+
+func (w *dbWriter) genHead() {
+
+}
+
+func (w *dbWriter) genFields() {
+
+}
+
+func (w *dbWriter) Insert(rec []byte) error {
+    return nil
+}
+
+func (w *dbWriter) Append(rec []byte) error {
+    return nil
+}
+
+func (f *dbReader) verify() (bool, error) {
     if !(f.head.version == 3 || f.head.version == 0x83) {
         if f.head.version == 0x8b {
             err := fmt.Errorf("dBase IV version %d - partially known...", f.head.version)
     return true, nil
 }
 
-func (f *dBaseFile) readHead() {
+func (f *dbReader) readHead() {
     f.head.version = read1byte(f.base, 0x00)
     f.head.l_update = f.base[0x01:0x04]
     f.head.count = read4byte(f.base, 0x04)
     f.head.reserv = f.base[0x0C:0x20]
 }
 
-func (f *dBaseFile) readFields(nf uint16) {
+func (f *dbReader) readFields(nf uint16) {
     cur := uint32(0x20)
     for i := uint16(0); i < nf; i++ {
         f.fields[i].name = f.base[cur : cur+11]
     return
 }
 
-func (f *dBaseFile) Info() {
-    fmt.Printf("File version  : %d\n", f.head.version)
-    fmt.Printf("Last update   : %02d/%02d/%2d\n", f.head.l_update[1], f.head.l_update[2], uint16(f.head.l_update[0])+1900)
-    fmt.Printf("Number of recs: %d\n", f.head.count)
-    fmt.Printf("Header length : %d\n", f.head.header)
-    fmt.Printf("Record length : %d\n", f.head.lrecl)
+func (f *dbReader) Info() {
+    fmt.Printf("File version    : %d\n", f.head.version)
+    fmt.Printf("Last update     : %02d/%02d/%2d\n", f.head.l_update[1], f.head.l_update[2], uint16(f.head.l_update[0])+1900)
+    fmt.Printf("Number of recs  : %d\n", f.head.count)
+    fmt.Printf("Header length   : %d\n", f.head.header)
+    fmt.Printf("Record length   : %d\n", f.head.lrecl)
 
     fmt.Printf("\nField Name\tType\tLength\tDecimal Pos\n")
     for _, v := range f.fields {
     fmt.Printf("\n")
 }
 
-func (f *dBaseFile) Print(flags int, delim byte, deleted byte) {
+func (f *dbReader) String() (s string) {
+    s = fmt.Sprintf("File version    : %d\n", f.head.version) +
+    fmt.Sprintf("Last update     : %02d/%02d/%2d\n", f.head.l_update[1], f.head.l_update[2], uint16(f.head.l_update[0])+1900) +
+    fmt.Sprintf("Number of recs  : %d\n", f.head.count) +
+    fmt.Sprintf("Header length   : %d\n", f.head.header) +
+    fmt.Sprintf("Record length   : %d\n", f.head.lrecl) +
+    fmt.Sprintf("\nField Name\tType\tLength\tDecimal Pos\n")
+    for _, v := range f.fields {
+        s += fmt.Sprintf("%-16s\t  %c\t  %3d\t  %3d\n", v.name, v.genre, v.length, v.dec_point)
+    }
+    return
+}
+
+func (f *dbReader) Print(flags int, delim byte, deleted byte) {
     var l uint8
     var nf = len(f.fields)
     var buffer []byte
     }
 }
 
-func (f *dBaseFile) Process() {
+func (f *dbReader) Process() {
     offset := f.head.header
     rlen := f.head.lrecl
     data := f.base[offset:]