LensStudio:Subprocess.Writable
ClassStream interface for writing to subprocess stdin.
Index
Example
const Subprocess = await import('LensStudio:Subprocess');
// Writable is the stdin stream of a Subprocess.
// Method: write(data: Uint8Array | string) => number (bytes written)
const proc = Subprocess.Subprocess.create('cat', [], {} as any);
this.connections.push(
proc.stdout.connect((data: Editor.Buffer) => {
console.log(`cat echoed back: ${data.toString().length} bytes`);
})
);
this.connections.push(
proc.onExit.connect((code: number) => {
console.log(`cat exited with code: ${code}`);
})
);
proc.start();
// Write a string to stdin; returns number of bytes written
const bytesWritten = proc.stdin.write('Hello from Writable\n');
console.log(`Writable.write returned: ${bytesWritten} bytes written`);
// Can also write Uint8Array
const binaryData = new Uint8Array([72, 101, 108, 108, 111, 10]); // "Hello\n"
const bytesWritten2 = proc.stdin.write(binaryData);
console.log(`Writable.write (binary): ${bytesWritten2} bytes written`);
// Kill after writing
proc.kill();
Extends
Methods
getTypeName()
staticgetTypeName():string
Returns the type name of this class.
Returns
string
Overrides
getTypeName()
getTypeName():
string
Returns the name of this object's type.
Returns
string
Inherited from
isOfType()
isOfType(
type):boolean
Returns true if the object is of the specified type.
Parameters
| Parameter | Type |
|---|---|
type | string |
Returns
boolean
Inherited from
isSame()
isSame(
other):boolean
Returns true if this object refers to the same instance as the given object.
Parameters
| Parameter | Type |
|---|---|
other | ScriptObject |
Returns
boolean
Inherited from
write()
write(
data):number
Write data to the stream and return the number of bytes written.
Parameters
| Parameter | Type |
|---|---|
data | string | Uint8Array<ArrayBufferLike> |
Returns
number