Add support for ASCII tags

This commit is contained in:
Jim Rybarski committed 2018-08-17 11:43:51 -05:00
1 parent daf23f34a0
commit ff1d31533b
4 files changed
+54 -12

No files matched your search

+11
View File
@@ -2,6 +2,7 @@ use std::io::{self, Read, Seek};
use std::mem;
use num_traits::{FromPrimitive, Num};
use std::collections::HashMap;
use std::string::FromUtf8Error;
use ::{ColorType, TiffError, TiffResult};
@@ -279,6 +280,16 @@ impl<R: Read + Seek> Decoder<R> {
self.reader.read_u32()
}
/// Reads a string
#[inline]
pub fn read_string(&mut self, length: usize) -> Result<String, FromUtf8Error> {
let mut out = String::with_capacity(length);
self.reader.read_to_string(&mut out);
// Strings may be null-terminated, so we trim anything downstream of the null byte
let trimmed = out.bytes().take_while(|&n| n != 0).collect::<Vec<u8>>();
String::from_utf8(trimmed)
}
/// Reads a TIFF IFA offset/value field
#[inline]
pub fn read_offset(&mut self) -> Result<[u8; 4], io::Error> {