MCPcopy
hub / github.com/micro-editor/micro / Serialize

Method Serialize

internal/buffer/serialize.go:24–56  ·  view source on GitHub ↗

Serialize serializes the buffer to config.ConfigDir/buffers

()

Source from the content-addressed store, hash-verified

22
23// Serialize serializes the buffer to config.ConfigDir/buffers
24func (b *Buffer) Serialize() error {
25 if !b.Settings["savecursor"].(bool) && !b.Settings["saveundo"].(bool) {
26 return nil
27 }
28 if b.Path == "" {
29 return nil
30 }
31
32 var buf bytes.Buffer
33 err := gob.NewEncoder(&buf).Encode(SerializedBuffer{
34 b.EventHandler,
35 b.GetActiveCursor().Loc,
36 b.ModTime,
37 })
38 if err != nil {
39 return err
40 }
41
42 name, resolveName := util.DetermineEscapePath(filepath.Join(config.ConfigDir, "buffers"), b.AbsPath)
43 err = util.SafeWrite(name, buf.Bytes(), true)
44 if err != nil {
45 return err
46 }
47
48 if resolveName != "" {
49 err = util.SafeWrite(resolveName, []byte(b.AbsPath), true)
50 if err != nil {
51 return err
52 }
53 }
54
55 return nil
56}
57
58// Unserialize loads the buffer info from config.ConfigDir/buffers
59func (b *Buffer) Unserialize() error {

Callers 2

saveToFileMethod · 0.95
FiniMethod · 0.95

Calls 5

GetActiveCursorMethod · 0.95
DetermineEscapePathFunction · 0.92
SafeWriteFunction · 0.92
JoinMethod · 0.80
BytesMethod · 0.80

Tested by

no test coverage detected