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
//! Utilities for working with `npz` files.
//!
//! NPZ files are a format used by numpy to store archives of multiple arrays.
//! The format itself is just a `.zip` file containing files with a `.npy` extension.
//!
//! When the `"npz"` feature is enabled, this module provides adapters around the
//! [`zip`][::zip] crate that read and write NPZ files.
//!
//! Even without the `"npz"` feature, this module always provides a set of utility functions
//! for converting between array names and filenames inside the zip file.
//! This allows you to use your own zip library. The [`examples` directory] includes an example
//! of how to read and write an npz without the feature.
//!
//! [`examples` directory]: https://github.com/ExpHP/npyz/tree/master/examples
pub use crate*;
/// Get the name of the array that would correspond to the given filename inside a zip file.
///
/// This tries to match the behavior of numpy's own npz-loading behavior:
///
/// * Case sensitive (only `.npy` files, not `.NPY` files)
/// * Allows weird characters like `/` and `.`. Makes no attempt to normalize paths.
/// * Treats an interior null as the end of the path. Notice that this means that multiple
/// different filenames could produce the same array name in a maliciously constructed zip.
///
/// Returns `None` if numpy would not consider the file to be an array.
///
/// _This function does not require any cargo features._
/// Get the filename in a zip that `np.savez` would use for a keyword argument.
///
/// **Note:** This does accept the name `"file"`, even though this cannot normally be used in `np.savez`
/// due to technical limitations. (numpy can read the file just fine)
///
/// _This function does not require any cargo features._
/// Get the filename in a zip that would be used for an array supplied as a positional
/// argument to `np.savez`.
///
/// _This function does not require any cargo features._