feat(napi): impl io::Read for Uint8Array (#2336)

This commit is contained in:
LongYinan 2024-10-30 16:15:43 +08:00 committed by GitHub
parent ac30f591dd
commit 00a3c13b42
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,4 +1,5 @@
use std::ffi::c_void;
use std::io::{self, Read};
use std::mem;
use std::ops::{Deref, DerefMut};
use std::ptr;
@ -679,6 +680,13 @@ impl Uint8Array {
}
}
impl Read for Uint8Array {
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
let mut inner: &[u8] = &*self;
Read::read(&mut inner, buf)
}
}
/// Zero copy Uint8ClampedArray slice shared between Rust and Node.js.
/// It can only be used in non-async context and the lifetime is bound to the fn closure.
/// If you want to use Node.js `Uint8ClampedArray` in async context or want to extend the lifetime, use `Uint8ClampedArray` instead.