Add fread(length) method

Fixed off-by-one write bug

Added test