Skip to content

⬅️ Back to Table of Contents

📄 FileEditor.js

📊 Analysis Summary

Metric Count
🔧 Functions 3
🧱 Classes 1
📦 Imports 5
📊 Variables & Constants 1

📚 Table of Contents

🛠️ File Location:

📂 playground/editors/FileEditor.js

📦 Imports

Name Source
StringInput flow
Element flow
BaseNodeEditor ../BaseNodeEditor.js
NodeUtils three/webgpu
arrayBuffer three/tsl

Variables & Constants

Name Type Kind Value Exported
blob Blob let/var new Blob( [ this.buffer ], { type: 'application/octet-stream' } )

Functions

FileEditor.getURL(): string

Returns: string

Calls:

  • URL.createObjectURL
Code
getURL() {

        if ( this.url === null ) {

            const blob = new Blob( [ this.buffer ], { type: 'application/octet-stream' } );

            this.url = URL.createObjectURL( blob );

        }

        return this.url;

    }

FileEditor.serialize(data: any): void

Parameters:

  • data any

Returns: void

Calls:

  • super.serialize
  • NodeUtils.arrayBufferToBase64
  • this.nameInput.getValue
Code
serialize( data ) {

        super.serialize( data );

        data.buffer = NodeUtils.arrayBufferToBase64( this.buffer );
        data.name = this.nameInput.getValue();

    }

FileEditor.deserialize(data: any): void

Parameters:

  • data any

Returns: void

Calls:

  • super.deserialize
  • NodeUtils.base64ToArrayBuffer
  • this.nameInput.setValue
Code
deserialize( data ) {

        super.deserialize( data );

        this.buffer = NodeUtils.base64ToArrayBuffer( data.buffer );
        this.nameInput.setValue( data.name );

    }

Classes

FileEditor

Class Code
export class FileEditor extends BaseNodeEditor {

    constructor( buffer = null, name = 'File' ) {

        super( 'File', arrayBuffer( buffer ), 250 );

        this.nameInput = new StringInput( name ).setReadOnly( true );

        this.add( new Element().add( this.nameInput ) );

        this.url = null;

    }

    set buffer( arrayBuffer ) {

        if ( this.url !== null ) {

            URL.revokeObjectUR( this.url );

        }

        this.value.value = arrayBuffer;
        this.url = null;

    }

    get buffer() {

        return this.value.value;

    }

    getURL() {

        if ( this.url === null ) {

            const blob = new Blob( [ this.buffer ], { type: 'application/octet-stream' } );

            this.url = URL.createObjectURL( blob );

        }

        return this.url;

    }

    serialize( data ) {

        super.serialize( data );

        data.buffer = NodeUtils.arrayBufferToBase64( this.buffer );
        data.name = this.nameInput.getValue();

    }

    deserialize( data ) {

        super.deserialize( data );

        this.buffer = NodeUtils.base64ToArrayBuffer( data.buffer );
        this.nameInput.setValue( data.name );

    }

}

Methods

getURL(): string
Code
getURL() {

        if ( this.url === null ) {

            const blob = new Blob( [ this.buffer ], { type: 'application/octet-stream' } );

            this.url = URL.createObjectURL( blob );

        }

        return this.url;

    }
serialize(data: any): void
Code
serialize( data ) {

        super.serialize( data );

        data.buffer = NodeUtils.arrayBufferToBase64( this.buffer );
        data.name = this.nameInput.getValue();

    }
deserialize(data: any): void
Code
deserialize( data ) {

        super.deserialize( data );

        this.buffer = NodeUtils.base64ToArrayBuffer( data.buffer );
        this.nameInput.setValue( data.name );

    }