impl read and write for buffer