1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/*! A library for parsing and extracting content of [LHA/LZH](https://en.wikipedia.org/wiki/LHA_(file_format)) archives.
This library is for easy parsing of LHA headers and allows to read files compressed with some of the
methods used by the archive format.
This library does not provide high level methods for creating files or directories from the extracted archives.
There are many extensions to the base LHA headers, used by many different archive programs, in many different
operating systems. This library only allows for parsing some basic properties of the archived files, such as
file path names and last modification timestamps.
The [LhaHeader] exposes properties and methods to inspect the raw content of header extensions, as well as
extended header data and may be explored by the user program in case extra archive properties are needed to be read.
LHA header levels: 0, 1, 2 and 3 are recognized.
## Compression methods
You may include or opt out of some of the decoders:
```toml
[dependencies.delharc]
version = "0.7"
default-features = false
features = ["std", "lh1"] # select desired features
```
`lh1` and `lz` features are enabled by **default**.
When using `default-features = false` the `std` feature needs to be added back along with other
compression method features. Otherwise the library will be compiled in the `no_std` mode.
| identifier | decoder | feature | description
|------------|--------------------|---------|------------
| `-lh0-` | PassthroughDecoder | | no compression
| `-lh1-` | Lh1Decoder | lh1 | LHarc version 1, 4kB sliding window, dynamic huffman
| `-lh4-` | Lh5Decoder | | LHarc version 2, 4kB sliding window, static huffman
| `-lh5-` | Lh5Decoder | | LHarc version 2, 8kB sliding window, static huffman
| `-lh6-` | Lh7Decoder | | LHarc version 2, 32kB sliding window, static huffman
| `-lh7-` | Lh7Decoder | | LHarc version 2, 64kB sliding window, static huffman
| `-lhd-` | unsupported | | an empty directory, data should be empty and should be skipped
| `-lhx-` | LhxDecoder | lhx | UNLHA32.DLL method, 128-512kb sliding window, static huffman
| `-lz4-` | PassthroughDecoder | | no compression
| `-lzs-` | LzsDecoder | lz | LArc, 2kb sliding window
| `-lz5-` | Lz5Decoder | lz | LArc, 4kb sliding window
| `-pm0-` | PassthroughDecoder | | no compression
| `-pm1-` | unsupported | N/A | PMarc, 8 Kb sliding window, static huffman
| `-pm2-` | unsupported | N/A | PMarc, 4 Kb sliding window, static huffman
*/
/*!
## No std
With `std` feature enabled, [`error::LhaError`] converts to [`std::io::Error`] via the [`From`] trait
and [`stub_io::Read`] is implemented for all types that implement [`std::io::Read`].
In this instance to read decompressed files, callers should access the [`LhaDecodeReader`] using
[`std::io::Read`] trait methods.
Without the `std` feature enabled `delharc` is compiled without the `std` library.
The extern crate `alloc` is still required though. Because [`std::io`] is missing,
in this instance callers should interface the [`LhaDecodeReader`] using [`stub_io::Read`]
trait directly. [`stub_io::Read`] is implemented initially for `&[u8]` slices and `Box<R: Read>`
and can be implemented for other types.
When compiled without `std`: [`stub_io::Read`], [`stub_io::Take`] and `UnexpectedEofError` are
re-exported directly under the crate root. `UnexpectedEofError` is only available in `no_std`.
```ignore
use delharc::{LhaDecodeReader, LhaError, LhaResult, Read, UnexpectedEofError};
const DATA: &[u8] = include_bytes!("file.lzh");
//...
let lha_reader = LhaDecodeReader::new(DATA).unwrap();
```
*/
// https://web.archive.org/web/20240916153830/https://archive.gamedev.net/archive/reference/articles/article295.html
extern crate alloc;
pub
pub
pub
// Various parsers assume usize has enough bits and will break on < 32-bits.
const _: usize = as usize - 1;
pub use LhaDecodeReader;
pub use ;
pub use ;
pub use ;
use Path;
use File;
/// Attempt to open a file from a filesystem in read-only mode and on success return an instance of
/// [LhaDecodeReader] with the first parsed LHA file header, ready to decode the content of the first
/// archived file.
///
/// # `no_std`
/// Available only with `std` feature enabled.
///
/// # Errors
/// This function will return an error if an opened file is not an LHA/LZH file or the header couldn't
/// be recognized. Other errors may also be returned from [File::open] and from attempts to read the file.