Skip to content

Commit

Permalink
Merge pull request #36 from Ritchie6/main
Browse files Browse the repository at this point in the history
Wrappers for Read and Write functions are added, namely- the ReadString and WriteString functions
  • Loading branch information
0xnullifier authored Dec 18, 2024
2 parents f4be312 + 0b8c7e3 commit 0adc607
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions mermoria.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ func (m *Memoria) Write(key string, val []byte) error {
return m.WriteStream(key, bytes.NewReader(val), false)
}

// WriteString is a wrapper for Write that takes a string and writes it as bytes
func (m *Memoria) WriteString(key, val string) error {
return m.Write(key, []byte(val))
}

// writes the data given by the io.reader performs explicit sync if mentioned otherwise
// depedning on the physical media it sync
func (m *Memoria) WriteStream(key string, r io.Reader, sync bool) error {
Expand Down Expand Up @@ -201,6 +206,15 @@ func (m *Memoria) Read(key string) ([]byte, error) {
return io.ReadAll(rc)
}

// ReadString is a wrapper around Read that returns the value as a string
func (m *Memoria) ReadString(key string) (string, error) {
val, err := m.Read(key)
if err != nil {
return "", err
}
return string(val), nil
}

// ReadStream takes the key and a bool byPassCache to bypass the cache and laziliy
// delete all the contents of cache for the hit

Expand Down

0 comments on commit 0adc607

Please sign in to comment.