You are reading content from Scuttlebutt
User has chosen not to be hosted publicly
@Hendrik Peter %PegnLz2UF/D7Iq6BPMXl0+enDntfUgRm+BBqOiMth4I=.sha256

hey!

what is it you're trying to do exactly?
you want to read and write files or would you like to create random bits of information?

User has chosen not to be hosted publicly
@Hendrik Peter %Z3PpwA7APDlTFXWMKrhwHj4JfrQfARoAwS+AZNCaAxs=.sha256

nice!
The offset file will be a json file so you could potentially read it like this:

{:ok, body} = File.read(log.offset)

Then you should be able to decode the body with the Jason library.

While testing this for myself I noticed that my computer had a lot of issues reading the huge file however.
Alternatively you could execute a command on your file-system instead (through a .sh script) with grep and sed to grab strings from your offset. You can see an example of sed here:

https://git.picodevelopment.nl/hendrikpeter/tmux-mac/blob/master/segments/weather.sh#L61 (I'm reading "icon": "someicon" in that line there)

User has chosen not to be hosted publicly
@mikey %bUttEH3IOq9SYLWDgTK4taV3cwT9+go2nzkCVFmt4Bg=.sha256

The offset file will be a json file

hi, if you mean the ~/.ssb/flume/log.offset file, this isn't a json file. it's a flumelog-offset file, an append-only log format where the records in our case are json.

@Hendrik Peter %vIAThZDwiPMF6BZArIX7yLoEEoJRbVZiP2Nmq4W1yME=.sha256

ah you're right @dinoƧ𝔸Ⓤᖇ. neat bit of code there there @punkmonk!

You could potentially make it a tad more tolerant by dealing with the {:error, reason} and hinting your supervisor how to act (depends on how you set up the supervisor)

so

case {:ok, contents} = :file.pread(io_device, offset, bytes) do
  {:ok, contents } -> IO.puts contents
  {:error, reason  } -> raise "oops", reason
end
@Hendrik Peter %ZqCqfdWItKTbIPmT8XYYMvjeouKDefrtDjf2ixEyNOg=.sha256

What am I writing. sorry that first line needs to be

case  :file.pread(io_device, offset, bytes) do

ofc... sorry 'bout that

User has chosen not to be hosted publicly
Join Scuttlebutt now