From 8f2d17140468512372ccd3aeebb0d505c607b977 Mon Sep 17 00:00:00 2001 From: snek Date: Tue, 21 May 2024 15:50:59 -0700 Subject: feat(node): buffer isUtf8/isAscii (#23928) Fixes: https://github.com/denoland/deno/issues/23657 Implements `isUtf8` and `isAscii` as ops. --- ext/node/ops/buffer.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 ext/node/ops/buffer.rs (limited to 'ext/node/ops/buffer.rs') diff --git a/ext/node/ops/buffer.rs b/ext/node/ops/buffer.rs new file mode 100644 index 000000000..74a011ab8 --- /dev/null +++ b/ext/node/ops/buffer.rs @@ -0,0 +1,13 @@ +// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. + +use deno_core::op2; + +#[op2(fast)] +pub fn op_is_ascii(#[buffer] buf: &[u8]) -> bool { + buf.is_ascii() +} + +#[op2(fast)] +pub fn op_is_utf8(#[buffer] buf: &[u8]) -> bool { + std::str::from_utf8(buf).is_ok() +} -- cgit v1.2.3