MCPcopy Create free account
hub / github.com/awslabs/llrt / write

Function write

modules/llrt_buffer/src/buffer.rs:426–461  ·  view source on GitHub ↗
(
    this: This<Object<'js>>,
    ctx: Ctx<'js>,
    string: String,
    args: Rest<Value<'js>>,
)

Source from the content-addressed store, hash-verified

424 });
425
426 let length = (end_index - start_index).max(0) as usize;
427 let new_offset = (view_offset + start_index).max(0) as usize;
428
429 Buffer::from_array_buffer_offset_length(&ctx, array_buffer, new_offset, length)
430}
431
432fn to_string(
433 this: This<Object<'_>>,
434 ctx: Ctx,
435 encoding: Opt<String>,
436 start: Opt<i32>,
437 end: Opt<i32>,
438) -> Result<String> {
439 let typed_array = TypedArray::<u8>::from_object(this.0)?;
440 let bytes: &[u8] = typed_array.as_ref();
441
442 let start = start
443 .0
444 .map(|s| s.max(0) as usize)
445 .unwrap_or(0)
446 .min(bytes.len());
447 let end = end
448 .0
449 .map(|e| e.max(0) as usize)
450 .unwrap_or(bytes.len())
451 .min(bytes.len());
452 let bytes = &bytes[start..end];
453
454 let encoder = Encoder::from_optional_str(encoding.as_deref()).or_throw(&ctx)?;
455 encoder.encode_to_string(bytes, true).or_throw(&ctx)
456}
457
458fn write<'js>(
459 this: This<Object<'js>>,
460 ctx: Ctx<'js>,
461 string: String,
462 args: Rest<Value<'js>>,
463) -> Result<usize> {
464 let (offset, length, encoding) = get_write_parameters(&ctx, &args, this.0.len())?;

Callers 1

write_file_syncFunction · 0.50

Calls 8

get_write_parametersFunction · 0.85
fromFunction · 0.85
safe_byte_sliceFunction · 0.85
or_throwMethod · 0.80
as_labelMethod · 0.80
decode_from_stringMethod · 0.80
lenMethod · 0.45
get_array_bufferMethod · 0.45

Tested by

no test coverage detected