flash: implement dynamic buffer size (close #111)