steemit / steem-python

The official Python (3) library for the Steem Blockchain.
https://steem.io
MIT License
153 stars 99 forks source link

Example syncing blockchain to flat file: return EOF if file empty #48

Closed MarneeDear closed 7 years ago

MarneeDear commented 7 years ago

Issue #47

Added block to get_last_line to check if the target file is empty and return EOF if empty.

fp.read() will return EOF if a file is empty.

The problem was with the seek. If there were no lines in the file, the seek function would fail with Invalid Index.

Netherdrake commented 7 years ago

get_last_line should fail, that is the correct behavior.

The purpose of this function is to return the json of the latest block, so if the file is empty, there is no latest block.

MarneeDear commented 7 years ago

If the file is empty it is also the first time the user has tried to get the blockchain.

What about the case where this is the first time you are downloading the blockchain?

In that case also the file will be empty. How are users supposed to get the blockchain with this example if it is their first time trying to get the blockchain?

Netherdrake commented 7 years ago

I've just read the example code, and determined my previous comment is invalid. Your patch does cover the edge case of file existing, but being completely empty.

Apologies for speaking out too hastily.

MarneeDear commented 7 years ago

Thanks!