summaryrefslogtreecommitdiff
path: root/ext/node/ops/zlib/mode.rs
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2023-04-24 12:22:21 +0200
committerGitHub <noreply@github.com>2023-04-24 12:22:21 +0200
commit1f0360c07382dbd86066d1aa8aa4bae34aff18c5 (patch)
treecc82d00aea829f0b3d3949f40df9696b099ee662 /ext/node/ops/zlib/mode.rs
parent28e2c7204fe02304a8fc3339d7758eec0f64f723 (diff)
refactor(ext/node): reorganize ops (#18799)
Move all op related code of "ext/node" to "ext/node/ops" module. These files were unnecessarily scattered around the extension.
Diffstat (limited to 'ext/node/ops/zlib/mode.rs')
-rw-r--r--ext/node/ops/zlib/mode.rs71
1 files changed, 71 insertions, 0 deletions
diff --git a/ext/node/ops/zlib/mode.rs b/ext/node/ops/zlib/mode.rs
new file mode 100644
index 000000000..ef89805ba
--- /dev/null
+++ b/ext/node/ops/zlib/mode.rs
@@ -0,0 +1,71 @@
+// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
+
+use libz_sys as sys;
+
+#[derive(Debug)]
+pub enum Error {
+ BadArgument,
+}
+
+impl std::fmt::Display for Error {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ match self {
+ Error::BadArgument => write!(f, "bad argument"),
+ }
+ }
+}
+
+impl std::error::Error for Error {}
+
+macro_rules! repr_i32 {
+ ($(#[$meta:meta])* $vis:vis enum $name:ident {
+ $($(#[$vmeta:meta])* $vname:ident $(= $val:expr)?,)*
+ }) => {
+ $(#[$meta])*
+ $vis enum $name {
+ $($(#[$vmeta])* $vname $(= $val)?,)*
+ }
+
+ impl core::convert::TryFrom<i32> for $name {
+ type Error = Error;
+
+ fn try_from(v: i32) -> Result<Self, Self::Error> {
+ match v {
+ $(x if x == $name::$vname as i32 => Ok($name::$vname),)*
+ _ => Err(Error::BadArgument),
+ }
+ }
+ }
+ }
+ }
+
+repr_i32! {
+ #[repr(i32)]
+ #[derive(Clone, Copy, Debug, PartialEq, Default)]
+ pub enum Mode {
+ #[default]
+ None,
+ Deflate,
+ Inflate,
+ Gzip,
+ Gunzip,
+ DeflateRaw,
+ InflateRaw,
+ Unzip,
+ }
+}
+
+repr_i32! {
+ #[repr(i32)]
+ #[derive(Clone, Copy, Debug, PartialEq, Default)]
+ pub enum Flush {
+ #[default]
+ None = sys::Z_NO_FLUSH,
+ Partial = sys::Z_PARTIAL_FLUSH,
+ Sync = sys::Z_SYNC_FLUSH,
+ Full = sys::Z_FULL_FLUSH,
+ Finish = sys::Z_FINISH,
+ Block = sys::Z_BLOCK,
+ Trees = sys::Z_TREES,
+ }
+}