buffer example
This commit is contained in:
parent
aa77c8ff97
commit
8b4e7af67f
7 changed files with 20 additions and 0 deletions
|
@ -18,6 +18,12 @@ impl From<Vec<u8>> for Buffer {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<&[u8]> for Buffer {
|
||||
fn from(inner: &[u8]) -> Self {
|
||||
Buffer::from(inner.to_owned())
|
||||
}
|
||||
}
|
||||
|
||||
impl AsRef<[u8]> for Buffer {
|
||||
fn as_ref(&self) -> &[u8] {
|
||||
self.inner.as_slice()
|
||||
|
|
|
@ -34,6 +34,7 @@ Generated by [AVA](https://avajs.dev).
|
|||
export function concatStr(mutS: string): string␊
|
||||
export function concatUtf16(s: string): string␊
|
||||
export function concatLatin1(s: string): string␊
|
||||
export function getBuffer(): Buffer␊
|
||||
export class Animal {␊
|
||||
readonly kind: Kind␊
|
||||
constructor(kind: Kind, name: string)␊
|
||||
|
|
Binary file not shown.
|
@ -22,6 +22,7 @@ import {
|
|||
throwError,
|
||||
readPackageJson,
|
||||
getPackageJsonName,
|
||||
getBuffer,
|
||||
} from '../'
|
||||
|
||||
test('number', (t) => {
|
||||
|
@ -112,3 +113,7 @@ test('serde-json', (t) => {
|
|||
|
||||
t.is(getPackageJsonName(packageJson), 'napi-rs')
|
||||
})
|
||||
|
||||
test('buffer', (t) => {
|
||||
t.is(getBuffer().toString('utf-8'), 'Hello world')
|
||||
})
|
||||
|
|
1
examples/napi/index.d.ts
vendored
1
examples/napi/index.d.ts
vendored
|
@ -24,6 +24,7 @@ export function contains(source: string, target: string): boolean
|
|||
export function concatStr(mutS: string): string
|
||||
export function concatUtf16(s: string): string
|
||||
export function concatLatin1(s: string): string
|
||||
export function getBuffer(): Buffer
|
||||
export class Animal {
|
||||
readonly kind: Kind
|
||||
constructor(kind: Kind, name: string)
|
||||
|
|
|
@ -13,3 +13,4 @@ mod number;
|
|||
mod object;
|
||||
mod serde;
|
||||
mod string;
|
||||
mod typed_array;
|
||||
|
|
6
examples/napi/src/typed_array.rs
Normal file
6
examples/napi/src/typed_array.rs
Normal file
|
@ -0,0 +1,6 @@
|
|||
use napi::bindgen_prelude::*;
|
||||
|
||||
#[napi]
|
||||
fn get_buffer() -> Buffer {
|
||||
String::from("Hello world").as_bytes().into()
|
||||
}
|
Loading…
Reference in a new issue