| 30 | } |
| 31 | |
| 32 | pub fn load(&mut self) -> io::Result<()> { |
| 33 | if self.path.is_none() { |
| 34 | return Ok(()); |
| 35 | } |
| 36 | |
| 37 | let mut file = match File::open(self.path.as_ref().unwrap()) { |
| 38 | Ok(file) => file, |
| 39 | Err(ref e) if e.kind() == io::ErrorKind::NotFound => return Ok(()), |
| 40 | Err(e) => return Err(e), |
| 41 | }; |
| 42 | file.lock_shared()?; |
| 43 | |
| 44 | if self.last_offset > 0 { |
| 45 | file.seek(SeekFrom::Start(self.last_offset))?; |
| 46 | } |
| 47 | |
| 48 | let mut file = BufReader::new(file); |
| 49 | let mut buf = [0; 16]; |
| 50 | loop { |
| 51 | match file.read_exact(&mut buf) { |
| 52 | Ok(()) => self.filter.insert(u128::from_le_bytes(buf)), |
| 53 | Err(ref e) if e.kind() == io::ErrorKind::UnexpectedEof => return Ok(()), |
| 54 | Err(e) => return Err(e), |
| 55 | }; |
| 56 | |
| 57 | self.last_offset += 16; |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | pub fn save(&mut self) -> io::Result<()> { |
| 62 | if self.path.is_none() || self.pending.is_empty() { |