summaryrefslogtreecommitdiffstats
path: root/vendor/content_inspector
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 12:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 12:47:55 +0000
commit2aadc03ef15cb5ca5cc2af8a7c08e070742f0ac4 (patch)
tree033cc839730fda84ff08db877037977be94e5e3a /vendor/content_inspector
parentInitial commit. (diff)
downloadcargo-upstream.tar.xz
cargo-upstream.zip
Adding upstream version 0.70.1+ds1.upstream/0.70.1+ds1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/content_inspector')
-rw-r--r--vendor/content_inspector/.cargo-checksum.json1
-rw-r--r--vendor/content_inspector/Cargo.toml25
-rw-r--r--vendor/content_inspector/LICENSE-APACHE201
-rw-r--r--vendor/content_inspector/LICENSE-MIT17
-rw-r--r--vendor/content_inspector/README.md65
-rw-r--r--vendor/content_inspector/examples/inspect.rs36
-rw-r--r--vendor/content_inspector/src/lib.rs218
-rw-r--r--vendor/content_inspector/testdata/create_text_files.py18
-rw-r--r--vendor/content_inspector/testdata/file_sources.md3
-rw-r--r--vendor/content_inspector/testdata/test.jpgbin0 -> 1523 bytes
-rw-r--r--vendor/content_inspector/testdata/test.pdf58
-rw-r--r--vendor/content_inspector/testdata/test.pngbin0 -> 251 bytes
-rw-r--r--vendor/content_inspector/testdata/text_UTF-16BE-BOM.txtbin0 -> 122 bytes
-rw-r--r--vendor/content_inspector/testdata/text_UTF-16LE-BOM.txtbin0 -> 122 bytes
-rw-r--r--vendor/content_inspector/testdata/text_UTF-32BE-BOM.txtbin0 -> 232 bytes
-rw-r--r--vendor/content_inspector/testdata/text_UTF-32LE-BOM.txtbin0 -> 232 bytes
-rw-r--r--vendor/content_inspector/testdata/text_UTF-8-BOM.txt2
-rw-r--r--vendor/content_inspector/testdata/text_UTF-8.txt2
18 files changed, 646 insertions, 0 deletions
diff --git a/vendor/content_inspector/.cargo-checksum.json b/vendor/content_inspector/.cargo-checksum.json
new file mode 100644
index 0000000..fe43d36
--- /dev/null
+++ b/vendor/content_inspector/.cargo-checksum.json
@@ -0,0 +1 @@
+{"files":{},"package":"b7bda66e858c683005a53a9a60c69a4aca7eeaa45d124526e389f7aec8e62f38"} \ No newline at end of file
diff --git a/vendor/content_inspector/Cargo.toml b/vendor/content_inspector/Cargo.toml
new file mode 100644
index 0000000..cf50d71
--- /dev/null
+++ b/vendor/content_inspector/Cargo.toml
@@ -0,0 +1,25 @@
+# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
+#
+# When uploading crates to the registry Cargo will automatically
+# "normalize" Cargo.toml files for maximal compatibility
+# with all versions of Cargo and also rewrite `path` dependencies
+# to registry (e.g. crates.io) dependencies
+#
+# If you believe there's an error in this file please file an
+# issue against the rust-lang/cargo repository. If you're
+# editing this file be aware that the upstream Cargo.toml
+# will likely look very different (and much more reasonable)
+
+[package]
+name = "content_inspector"
+version = "0.2.4"
+authors = ["David Peter <mail@david-peter.de>"]
+description = "Fast inspection of binary buffers to guess/determine the encoding"
+homepage = "https://github.com/sharkdp/content_inspector"
+readme = "README.md"
+keywords = ["unicode", "encoding", "binary", "text", "library"]
+categories = ["encoding"]
+license = "MIT/Apache-2.0"
+repository = "https://github.com/sharkdp/content_inspector"
+[dependencies.memchr]
+version = "2"
diff --git a/vendor/content_inspector/LICENSE-APACHE b/vendor/content_inspector/LICENSE-APACHE
new file mode 100644
index 0000000..261eeb9
--- /dev/null
+++ b/vendor/content_inspector/LICENSE-APACHE
@@ -0,0 +1,201 @@
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
diff --git a/vendor/content_inspector/LICENSE-MIT b/vendor/content_inspector/LICENSE-MIT
new file mode 100644
index 0000000..969d061
--- /dev/null
+++ b/vendor/content_inspector/LICENSE-MIT
@@ -0,0 +1,17 @@
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/vendor/content_inspector/README.md b/vendor/content_inspector/README.md
new file mode 100644
index 0000000..f1e2dc1
--- /dev/null
+++ b/vendor/content_inspector/README.md
@@ -0,0 +1,65 @@
+# content_inspector
+
+[![Crates.io](https://img.shields.io/crates/v/content_inspector.svg)](https://crates.io/crates/content_inspector)
+[![Documentation](https://docs.rs/content_inspector/badge.svg)](https://docs.rs/content_inspector)
+
+A simple library for *fast* inspection of binary buffers to guess the type of content.
+
+This is mainly intended to quickly determine whether a given buffer contains "binary"
+or "text" data. Programs like `grep` or `git diff` use similar mechanisms to decide whether
+to treat some files as "binary data" or not.
+
+The analysis is based on a very simple heuristic: Searching for NULL bytes
+(indicating "binary" content) and the detection of special [byte order
+marks](https://en.wikipedia.org/wiki/Byte_order_mark) (indicating a particular kind of textual
+encoding). Note that **this analysis can fail**. For example, even if unlikely, UTF-8-encoded
+text can legally contain NULL bytes. Conversely, some particular binary formats (like binary
+[PGM](https://en.wikipedia.org/wiki/Netpbm_format)) may not contain NULL bytes. Also, for
+performance reasons, only the first 1024 bytes are checked for the NULL-byte (if no BOM was
+detected).
+
+If this library reports a certain type of encoding (say `UTF_16LE`), there is **no guarantee** that
+the binary buffer can actually be decoded as UTF-16LE.
+
+## Usage
+
+```rust
+use content_inspector::{ContentType, inspect};
+
+assert_eq!(ContentType::UTF_8, inspect(b"Hello"));
+assert_eq!(ContentType::BINARY, inspect(b"\xFF\xE0\x00\x10\x4A\x46\x49\x46\x00"));
+
+assert!(inspect(b"Hello").is_text());
+```
+
+## CLI example
+
+This crate also comes with a small example command-line program (see [`examples/inspect.rs`](examples/inspect.rs)) that demonstrates the usage:
+```bash
+> inspect
+USAGE: inspect FILE [FILE...]
+
+> inspect testdata/*
+testdata/create_text_files.py: UTF-8
+testdata/file_sources.md: UTF-8
+testdata/test.jpg: binary
+testdata/test.pdf: binary
+testdata/test.png: binary
+testdata/text_UTF-16BE-BOM.txt: UTF-16BE
+testdata/text_UTF-16LE-BOM.txt: UTF-16LE
+testdata/text_UTF-32BE-BOM.txt: UTF-32BE
+testdata/text_UTF-32LE-BOM.txt: UTF-32LE
+testdata/text_UTF-8-BOM.txt: UTF-8-BOM
+testdata/text_UTF-8.txt: UTF-8
+```
+
+If you only want to detect whether something is a binary or text file, this is about a factor of 250 faster than `file --mime ...`.
+
+## License
+
+Licensed under either of
+
+ * Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
+ * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
+
+at your option.
diff --git a/vendor/content_inspector/examples/inspect.rs b/vendor/content_inspector/examples/inspect.rs
new file mode 100644
index 0000000..5103d46
--- /dev/null
+++ b/vendor/content_inspector/examples/inspect.rs
@@ -0,0 +1,36 @@
+extern crate content_inspector;
+
+use std::env;
+use std::fs::File;
+use std::io::{Error, Read};
+use std::path::Path;
+use std::process::exit;
+
+const MAX_PEEK_SIZE: usize = 1024;
+
+fn main() -> Result<(), Error> {
+ let mut args = env::args();
+
+ if args.len() < 2 {
+ eprintln!("USAGE: inspect FILE [FILE...]");
+ exit(1);
+ }
+
+ args.next();
+
+ for filename in args {
+ if !Path::new(&filename).is_file() {
+ continue;
+ }
+
+ let file = File::open(&filename)?;
+ let mut buffer: Vec<u8> = vec![];
+
+ file.take(MAX_PEEK_SIZE as u64).read_to_end(&mut buffer)?;
+
+ let content_type = content_inspector::inspect(&buffer);
+ println!("{}: {}", filename, content_type);
+ }
+
+ Ok(())
+}
diff --git a/vendor/content_inspector/src/lib.rs b/vendor/content_inspector/src/lib.rs
new file mode 100644
index 0000000..de846cc
--- /dev/null
+++ b/vendor/content_inspector/src/lib.rs
@@ -0,0 +1,218 @@
+//! A simple library for *fast* inspection of binary buffers to guess the type of content.
+//!
+//! This is mainly intended to quickly determine whether a given buffer contains "binary"
+//! or "text" data. Programs like `grep` or `git diff` use similar mechanisms to decide whether
+//! to treat some files as "binary data" or not.
+//!
+//! The analysis is based on a very simple heuristic: Searching for NULL bytes
+//! (indicating "binary" content) and the detection of special [byte order
+//! marks](https://en.wikipedia.org/wiki/Byte_order_mark) (indicating a particular kind of textual
+//! encoding). Note that **this analysis can fail**. For example, even if unlikely, UTF-8-encoded
+//! text can legally contain NULL bytes. Conversely, some particular binary formats (like binary
+//! [PGM](https://en.wikipedia.org/wiki/Netpbm_format)) may not contain NULL bytes. Also, for
+//! performance reasons, only the first 1024 bytes are checked for the NULL-byte (if no BOM was
+//! detected).
+//!
+//! If this library reports a certain type of encoding (say `UTF_16LE`), there is **no guarantee**
+//! that the binary buffer can *actually* be decoded as UTF-16LE.
+//!
+//! # Example
+//! ```
+//! use content_inspector::{ContentType, inspect};
+//!
+//! assert_eq!(ContentType::UTF_8, inspect(b"Hello"));
+//! assert_eq!(ContentType::BINARY, inspect(b"\xFF\xE0\x00\x10\x4A\x46\x49\x46\x00"));
+//!
+//! assert!(inspect(b"Hello").is_text());
+//! ```
+
+extern crate memchr;
+
+use memchr::memchr;
+use std::cmp::min;
+use std::fmt;
+
+const MAX_SCAN_SIZE: usize = 1024;
+
+/// The type of encoding that was detected (for "text" data) or `BINARY` for "binary" data.
+#[allow(non_camel_case_types)]
+#[derive(Copy, Clone, Debug, PartialEq)]
+pub enum ContentType {
+ /// "binary" data
+ BINARY,
+
+ /// UTF-8 encoded "text" data
+ UTF_8,
+
+ /// UTF-8 encoded "text" data with a byte order mark.
+ UTF_8_BOM,
+
+ /// UTF-16 encoded "text" data (little endian)
+ UTF_16LE,
+
+ /// UTF-16 encoded "text" data (big endian)
+ UTF_16BE,
+
+ /// UTF-32 encoded "text" data (little endian)
+ UTF_32LE,
+
+ /// UTF-32 encoded "text" data (big endian)
+ UTF_32BE,
+}
+
+impl ContentType {
+ /// Returns `true`, if the `ContentType` is `BINARY`.
+ pub fn is_binary(self) -> bool {
+ self == ContentType::BINARY
+ }
+
+ /// Returns `true`, if the `ContentType` is __not__ `BINARY`.
+ pub fn is_text(self) -> bool {
+ !self.is_binary()
+ }
+}
+
+impl fmt::Display for ContentType {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ use ContentType::*;
+
+ let name: &str = match *self {
+ BINARY => "binary",
+ UTF_8 => "UTF-8",
+ UTF_8_BOM => "UTF-8-BOM",
+ UTF_16LE => "UTF-16LE",
+ UTF_16BE => "UTF-16BE",
+ UTF_32LE => "UTF-32LE",
+ UTF_32BE => "UTF-32BE",
+ };
+ write!(f, "{}", name)
+ }
+}
+
+/// Common byte order marks
+/// (see https://en.wikipedia.org/wiki/Byte_order_mark)
+static BYTE_ORDER_MARKS: &[(&[u8], ContentType)] = &[
+ (&[0xEF, 0xBB, 0xBF], ContentType::UTF_8_BOM),
+ // UTF-32 needs to be checked before UTF-16 (overlapping BOMs)
+ (&[0x00, 0x00, 0xFE, 0xFF], ContentType::UTF_32BE),
+ (&[0xFF, 0xFE, 0x00, 0x00], ContentType::UTF_32LE),
+ (&[0xFE, 0xFF], ContentType::UTF_16BE),
+ (&[0xFF, 0xFE], ContentType::UTF_16LE),
+];
+
+/// Magic numbers for some filetypes that could otherwise be characterized as text.
+static MAGIC_NUMBERS: [&[u8]; 2] = [b"%PDF", b"\x89PNG"];
+
+/// Try to determine the type of content in the given buffer. See the crate documentation for a
+/// usage example and for more details on how this analysis is performed.
+///
+/// If the buffer is empty, the content type will be reported as `UTF_8`.
+pub fn inspect(buffer: &[u8]) -> ContentType {
+ use ContentType::*;
+
+ for &(bom, content_type) in BYTE_ORDER_MARKS {
+ if buffer.starts_with(bom) {
+ return content_type;
+ }
+ }
+
+ // Scan the first few bytes for zero-bytes
+ let scan_size = min(buffer.len(), MAX_SCAN_SIZE);
+ let has_zero_bytes = memchr(0x00, &buffer[..scan_size]).is_some();
+
+ if has_zero_bytes {
+ return BINARY;
+ }
+
+ if MAGIC_NUMBERS.iter().any(|magic| buffer.starts_with(magic)) {
+ return BINARY;
+ }
+
+ UTF_8
+}
+
+#[cfg(test)]
+mod tests {
+ use {inspect, ContentType::*};
+
+ #[test]
+ fn test_empty_buffer_utf_8() {
+ assert_eq!(UTF_8, inspect(b""));
+ }
+
+ #[test]
+ fn test_text_simple() {
+ assert_eq!(UTF_8, inspect("Simple UTF-8 string ☔".as_bytes()));
+ }
+
+ #[test]
+ fn test_text_utf8() {
+ assert_eq!(UTF_8, inspect(include_bytes!("../testdata/text_UTF-8.txt")));
+ }
+
+ #[test]
+ fn test_text_utf8_bom() {
+ assert_eq!(
+ UTF_8_BOM,
+ inspect(include_bytes!("../testdata/text_UTF-8-BOM.txt"))
+ );
+ }
+
+ #[test]
+ fn test_text_utf16le() {
+ assert_eq!(
+ UTF_16LE,
+ inspect(include_bytes!("../testdata/text_UTF-16LE-BOM.txt"))
+ );
+ }
+
+ #[test]
+ fn test_text_utf16be() {
+ assert_eq!(
+ UTF_16BE,
+ inspect(include_bytes!("../testdata/text_UTF-16BE-BOM.txt"))
+ );
+ }
+
+ #[test]
+ fn test_text_utf32le() {
+ assert_eq!(
+ UTF_32LE,
+ inspect(include_bytes!("../testdata/text_UTF-32LE-BOM.txt"))
+ );
+ }
+
+ #[test]
+ fn test_text_utf32be() {
+ assert_eq!(
+ UTF_32BE,
+ inspect(include_bytes!("../testdata/text_UTF-32BE-BOM.txt"))
+ );
+ }
+
+ #[test]
+ fn test_png() {
+ assert_eq!(BINARY, inspect(include_bytes!("../testdata/test.png")));
+ }
+
+ #[test]
+ fn test_jpg() {
+ assert_eq!(BINARY, inspect(include_bytes!("../testdata/test.jpg")));
+ }
+
+ #[test]
+ fn test_pdf() {
+ assert_eq!(BINARY, inspect(include_bytes!("../testdata/test.pdf")));
+ }
+
+ #[test]
+ fn test_is_text() {
+ assert!(UTF_8.is_text());
+ assert!(UTF_32LE.is_text());
+ }
+
+ #[test]
+ fn test_is_binary() {
+ assert!(BINARY.is_binary());
+ }
+}
diff --git a/vendor/content_inspector/testdata/create_text_files.py b/vendor/content_inspector/testdata/create_text_files.py
new file mode 100644
index 0000000..e1cd477
--- /dev/null
+++ b/vendor/content_inspector/testdata/create_text_files.py
@@ -0,0 +1,18 @@
+import codecs
+
+encodings = {
+ "UTF-8": ("utf-8", codecs.BOM_UTF8),
+ "UTF-16BE": ("utf_16_be", codecs.BOM_UTF16_BE),
+ "UTF-16LE": ("utf_16_le", codecs.BOM_UTF16_LE),
+ "UTF-32BE": ("utf_32_be", codecs.BOM_UTF32_BE),
+ "UTF-32LE": ("utf_32_le", codecs.BOM_UTF32_LE),
+}
+
+with open("text_UTF-8.txt", "rb") as source:
+ data = source.read()
+ text = data.decode("utf-8")
+
+ for name, (encoding, bom) in encodings.items():
+ with open("text_{}-BOM.txt".format(name), "wb") as target:
+ target.write(bom)
+ target.write(text.encode(encoding))
diff --git a/vendor/content_inspector/testdata/file_sources.md b/vendor/content_inspector/testdata/file_sources.md
new file mode 100644
index 0000000..e015564
--- /dev/null
+++ b/vendor/content_inspector/testdata/file_sources.md
@@ -0,0 +1,3 @@
+test.png: https://commons.wikimedia.org/wiki/File:PNG-Gradient.png
+test.jpg: https://commons.wikimedia.org/wiki/File:JPEG_example_JPG_RIP_001.jpg
+test.pdf: http://brendanzagaeski.appspot.com/0004.html
diff --git a/vendor/content_inspector/testdata/test.jpg b/vendor/content_inspector/testdata/test.jpg
new file mode 100644
index 0000000..0655464
--- /dev/null
+++ b/vendor/content_inspector/testdata/test.jpg
Binary files differ
diff --git a/vendor/content_inspector/testdata/test.pdf b/vendor/content_inspector/testdata/test.pdf
new file mode 100644
index 0000000..1c64181
--- /dev/null
+++ b/vendor/content_inspector/testdata/test.pdf
@@ -0,0 +1,58 @@
+%PDF-1.1
+%¥±ë
+
+1 0 obj
+ << /Type /Catalog
+ /Pages 2 0 R
+ >>
+endobj
+
+2 0 obj
+ << /Type /Pages
+ /Kids [3 0 R]
+ /Count 1
+ /MediaBox [0 0 300 144]
+ >>
+endobj
+
+3 0 obj
+ << /Type /Page
+ /Parent 2 0 R
+ /Resources
+ << /Font
+ << /F1
+ << /Type /Font
+ /Subtype /Type1
+ /BaseFont /Times-Roman
+ >>
+ >>
+ >>
+ /Contents 4 0 R
+ >>
+endobj
+
+4 0 obj
+ << /Length 55 >>
+stream
+ BT
+ /F1 18 Tf
+ 0 0 Td
+ (Hello World) Tj
+ ET
+endstream
+endobj
+
+xref
+0 5
+0000000000 65535 f
+0000000018 00000 n
+0000000077 00000 n
+0000000178 00000 n
+0000000457 00000 n
+trailer
+ << /Root 1 0 R
+ /Size 5
+ >>
+startxref
+565
+%%EOF
diff --git a/vendor/content_inspector/testdata/test.png b/vendor/content_inspector/testdata/test.png
new file mode 100644
index 0000000..b0e0aba
--- /dev/null
+++ b/vendor/content_inspector/testdata/test.png
Binary files differ
diff --git a/vendor/content_inspector/testdata/text_UTF-16BE-BOM.txt b/vendor/content_inspector/testdata/text_UTF-16BE-BOM.txt
new file mode 100644
index 0000000..2965321
--- /dev/null
+++ b/vendor/content_inspector/testdata/text_UTF-16BE-BOM.txt
Binary files differ
diff --git a/vendor/content_inspector/testdata/text_UTF-16LE-BOM.txt b/vendor/content_inspector/testdata/text_UTF-16LE-BOM.txt
new file mode 100644
index 0000000..fe3e8b9
--- /dev/null
+++ b/vendor/content_inspector/testdata/text_UTF-16LE-BOM.txt
Binary files differ
diff --git a/vendor/content_inspector/testdata/text_UTF-32BE-BOM.txt b/vendor/content_inspector/testdata/text_UTF-32BE-BOM.txt
new file mode 100644
index 0000000..3360d41
--- /dev/null
+++ b/vendor/content_inspector/testdata/text_UTF-32BE-BOM.txt
Binary files differ
diff --git a/vendor/content_inspector/testdata/text_UTF-32LE-BOM.txt b/vendor/content_inspector/testdata/text_UTF-32LE-BOM.txt
new file mode 100644
index 0000000..4db0501
--- /dev/null
+++ b/vendor/content_inspector/testdata/text_UTF-32LE-BOM.txt
Binary files differ
diff --git a/vendor/content_inspector/testdata/text_UTF-8-BOM.txt b/vendor/content_inspector/testdata/text_UTF-8-BOM.txt
new file mode 100644
index 0000000..64a7a02
--- /dev/null
+++ b/vendor/content_inspector/testdata/text_UTF-8-BOM.txt
@@ -0,0 +1,2 @@
+simple text and
+some characters like 🌂, 💖, ä, 𝄞, € and ∰
diff --git a/vendor/content_inspector/testdata/text_UTF-8.txt b/vendor/content_inspector/testdata/text_UTF-8.txt
new file mode 100644
index 0000000..26168a3
--- /dev/null
+++ b/vendor/content_inspector/testdata/text_UTF-8.txt
@@ -0,0 +1,2 @@
+simple text and
+some characters like 🌂, 💖, ä, 𝄞, € and ∰