read/write using length of buffer