mirror of
https://github.com/TxtDot/dalet-rs.git
synced 2024-11-21 16:26:21 +03:00
fix: decompress max capacity, clippy --fix
This commit is contained in:
parent
915c5c0a6d
commit
a5443bf0fc
9 changed files with 25 additions and 30 deletions
|
@ -1,5 +1,3 @@
|
|||
use std::u32::MAX;
|
||||
|
||||
use crate::daletl::{DlArgument, DlBody, DlPage, DlTag, DlTid};
|
||||
|
||||
use super::{utils, DaletPackDecodeError, TypeId};
|
||||
|
@ -20,7 +18,7 @@ impl<'a> Decoder<'a> {
|
|||
pub fn decode(&mut self) -> Result<DlPage, DaletPackDecodeError> {
|
||||
let mut array: Vec<DlTag> = Vec::new();
|
||||
|
||||
for _ in 0..MAX {
|
||||
for _ in 0..u32::MAX {
|
||||
let typeid = self.data.next();
|
||||
|
||||
match typeid {
|
||||
|
@ -88,7 +86,7 @@ impl<'a> Decoder<'a> {
|
|||
fn read_text(&mut self) -> Result<String, DaletPackDecodeError> {
|
||||
let mut str = String::new();
|
||||
|
||||
for _ in 0..MAX {
|
||||
for _ in 0..u32::MAX {
|
||||
let val = self
|
||||
.data
|
||||
.next()
|
||||
|
@ -107,7 +105,7 @@ impl<'a> Decoder<'a> {
|
|||
fn read_tag_array(&mut self) -> Result<Vec<DlTag>, DaletPackDecodeError> {
|
||||
let mut array = Vec::new();
|
||||
|
||||
for _ in 0..MAX {
|
||||
for _ in 0..u32::MAX {
|
||||
let typeid: TypeId = self
|
||||
.data
|
||||
.next()
|
||||
|
|
|
@ -3,8 +3,8 @@ use crate::daletl::{DlArgument, DlBody, DlPage, DlTag, DlTid, IsNull};
|
|||
use super::{utils, DaletPackError, TypeId};
|
||||
|
||||
pub fn encode(page: &DlPage) -> Result<Vec<u8>, DaletPackError> {
|
||||
Ok(utils::compress_zstd(&encode_no_compress(page)?)
|
||||
.map_err(|_| DaletPackError::ZstdCompressError)?)
|
||||
utils::compress_zstd(&encode_no_compress(page)?)
|
||||
.map_err(|_| DaletPackError::ZstdCompressError)
|
||||
}
|
||||
|
||||
pub fn encode_no_compress(page: &DlPage) -> Result<Vec<u8>, DaletPackError> {
|
||||
|
|
|
@ -1,9 +1,13 @@
|
|||
use std::u32::MAX;
|
||||
use std::io::{self, Read};
|
||||
use zstd::stream::read::Decoder;
|
||||
|
||||
pub fn compress_zstd(data: &[u8]) -> std::io::Result<Vec<u8>> {
|
||||
pub fn compress_zstd(data: &[u8]) -> io::Result<Vec<u8>> {
|
||||
zstd::bulk::compress(data, 22)
|
||||
}
|
||||
|
||||
pub fn decompress_zstd(data: &[u8]) -> std::io::Result<Vec<u8>> {
|
||||
zstd::bulk::decompress(data, MAX as usize)
|
||||
pub fn decompress_zstd(data: &[u8]) -> io::Result<Vec<u8>> {
|
||||
let mut decoder = Decoder::new(data)?;
|
||||
let mut decompressed = Vec::new();
|
||||
decoder.read_to_end(&mut decompressed)?;
|
||||
Ok(decompressed)
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ pub fn parse_gemtext(s: &str) -> Result<Page, GemTextParseError> {
|
|||
|
||||
match body.next() {
|
||||
Some(label) => page.push(P(
|
||||
vec![Navlink(label.trim().into(), url.into()).into()].into()
|
||||
vec![Navlink(label.trim().into(), url.into())].into()
|
||||
)),
|
||||
None => page.push(P(vec![Navlink(Body::Null, url.into())].into())),
|
||||
};
|
||||
|
|
|
@ -75,7 +75,7 @@ impl TryFrom<DlArgument> for TNArg {
|
|||
|
||||
fn try_from(value: DlArgument) -> Result<Self, Self::Error> {
|
||||
match value {
|
||||
DlArgument::Text(t) => Ok(TNArg::Text(t.into())),
|
||||
DlArgument::Text(t) => Ok(TNArg::Text(t)),
|
||||
DlArgument::Null => Ok(TNArg::Null),
|
||||
_ => Err(ConversionError),
|
||||
}
|
||||
|
|
|
@ -2,18 +2,12 @@ use crate::daletl::{DlArgument, DlBody, IsNull};
|
|||
|
||||
impl IsNull for DlBody {
|
||||
fn is_null(&self) -> bool {
|
||||
match self {
|
||||
Self::Null => true,
|
||||
_ => false,
|
||||
}
|
||||
matches!(self, Self::Null)
|
||||
}
|
||||
}
|
||||
|
||||
impl IsNull for DlArgument {
|
||||
fn is_null(&self) -> bool {
|
||||
match self {
|
||||
Self::Null => true,
|
||||
_ => false,
|
||||
}
|
||||
matches!(self, Self::Null)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,10 +24,9 @@ fn resolve_from_tags(tags: &Vec<Tag>) -> Option<String> {
|
|||
}
|
||||
}
|
||||
|
||||
Block(body, _) => match body {
|
||||
NNBody::Tags(tags) => return resolve_from_tags(tags),
|
||||
_ => {}
|
||||
},
|
||||
Block(NNBody::Tags(tags), _) => {
|
||||
return resolve_from_tags(tags);
|
||||
}
|
||||
|
||||
_ => {}
|
||||
};
|
||||
|
|
|
@ -17,15 +17,15 @@ macro_rules! iprint {
|
|||
}};
|
||||
}
|
||||
|
||||
pub fn compress_deflate(data: &Vec<u8>) -> std::io::Result<Vec<u8>> {
|
||||
pub fn compress_deflate(data: &[u8]) -> std::io::Result<Vec<u8>> {
|
||||
let mut c = flate2::write::DeflateEncoder::new(Vec::new(), Compression::default());
|
||||
c.write(data)?;
|
||||
c.write_all(data)?;
|
||||
c.finish()
|
||||
}
|
||||
|
||||
pub fn compress_zlib(data: &Vec<u8>) -> std::io::Result<Vec<u8>> {
|
||||
pub fn compress_zlib(data: &[u8]) -> std::io::Result<Vec<u8>> {
|
||||
let mut c = flate2::write::ZlibEncoder::new(Vec::new(), Compression::default());
|
||||
c.write(data)?;
|
||||
c.write_all(data)?;
|
||||
c.finish()
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ use dalet::parsers::gemtext::parse_gemtext;
|
|||
fn gem_text() {
|
||||
let text = include_str!("./gemtext.gmi");
|
||||
|
||||
let _ = parse_gemtext(&text).unwrap();
|
||||
let _ = parse_gemtext(text).unwrap();
|
||||
|
||||
// println!("{:#?}", parsed);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue