fs

package
v0.0.0-...-deba56b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 29, 2023 License: AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Overview

Package fs provides a k6 module that allows users to interact with files from the local filesystem as per the File API design document.

Index

Constants

View Source
const (
	// NotFoundError is emitted when a file is not found.
	NotFoundError errorKind = iota + 1

	// InvalidResourceError is emitted when a resource is invalid: for
	// instance when attempting to open a directory, which is not supported.
	InvalidResourceError

	// ForbiddenError is emitted when an operation is forbidden.
	ForbiddenError

	// TypeError is emitted when an incorrect type has been used.
	TypeError

	// EOFError is emitted when the end of a file has been reached.
	EOFError
)
View Source
const (
	// SeekModeStart sets the offset relative to the start of the file.
	SeekModeStart SeekMode = 0

	// SeekModeCurrent seeks relative to the current offset.
	SeekModeCurrent = 1

	// SeekModeEnd seeks relative to the end of the file.
	//
	// When using this mode the seek operation will move backwards from
	// the end of the file.
	SeekModeEnd = 2
)

Variables

This section is empty.

Functions

This section is empty.

Types

type File

type File struct {
	// Path holds the name of the file, as presented to [Open].
	Path string `json:"path"`
	// contains filtered or unexported fields
}

File represents a file and exposes methods to interact with it.

It is a wrapper around the [file] struct, which is meant to be directly exposed to the JS runtime.

func (*File) Read

func (f *File) Read(into goja.Value) *goja.Promise

Read the file's content, and writes it into the provided Uint8Array.

Resolves to either the number of bytes read during the operation or EOF (null) if there was nothing more to read.

It is possible for a read to successfully return with 0 bytes. This does not indicate EOF.

func (*File) Seek

func (f *File) Seek(offset goja.Value, whence goja.Value) *goja.Promise

Seek seeks to the given `offset` in the file, under the given `whence` mode.

The returned promise resolves to the new `offset` (position) within the file, which is expressed in bytes from the selected start, current, or end position depending the provided `whence`.

func (*File) Stat

func (f *File) Stat() *goja.Promise

Stat returns a promise that will resolve to a FileInfo instance describing the file.

type FileInfo

type FileInfo struct {
	// Name holds the base name of the file.
	Name string `json:"name"`

	// Size holds the size of the file in bytes.
	Size int64 `json:"size"`
}

FileInfo holds information about a file.

type ModuleInstance

type ModuleInstance struct {
	// contains filtered or unexported fields
}

ModuleInstance represents an instance of the fs module for a single VU.

func (*ModuleInstance) Exports

func (mi *ModuleInstance) Exports() modules.Exports

Exports implements the modules.Module interface and returns the exports of our module.

func (*ModuleInstance) Open

func (mi *ModuleInstance) Open(path goja.Value) *goja.Promise

Open opens a file and returns a promise that will resolve to a File instance

type RootModule

type RootModule struct {
	// contains filtered or unexported fields
}

RootModule is the global module instance that will create instances of our module for each VU.

func New

func New() *RootModule

New returns a pointer to a new RootModule instance.

func (*RootModule) NewModuleInstance

func (rm *RootModule) NewModuleInstance(vu modules.VU) modules.Instance

NewModuleInstance implements the modules.Module interface and returns a new instance of our module for the given VU.

type SeekMode

type SeekMode = int

SeekMode is used to specify the seek mode when seeking in a file.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL