pub fn read_limited<R: Read>(reader: R, limit: u64) -> Result<Option<Vec<u8>>>Expand description
Everything a reader holds, read a mebibyte at a time, or None as soon
as it has given more than limit bytes. music21’s readZipMember reads
a member so, rather than trusting the size its header claims.
use music21::common::filetools::read_limited;
assert_eq!(read_limited(&b"<score/>"[..], 8).unwrap(), Some(b"<score/>".to_vec()));
assert_eq!(read_limited(&b"<score/>"[..], 7).unwrap(), None);