explorer

package module
Version: v0.0.0-...-f3dbca5 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2022 License: MIT, Unlicense Imports: 3 Imported by: 1

README

explorer Go Reference


Integrates a simlpe Save As... or Open... mechanism to your Gio application.

What can it be used for?

Well, for anything that manipulates user's file. You can use os.Open to open and write file, but sometimes you want to know where to save the data, in those case Explorer is usefull.

Status

Currently, Explorer supports across Android, JS and Windows 10. It will return ErrAvailableAPI for any other platform that isn't supported.

Limitations

Edit file content via explorer.ReadFile():

It may not be possible to edit/write data using explorer.ReadFile(). Because of that, it returns a io.ReadCloser instead of io.ReadWriteCloser, since some operational systems (such as JS) doesn't allow us to modify the file. However, you can use type-assertion to check if it's possible or not:

reader, _ := explorer.ReadFile()
if f, ok := reader.(*os.File); ok {
    // We can use `os.File.Write` in that case. It's NOT possible in all OSes.
    f.Write(...)
}
Select folders:

It's not possible to select folders.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrUserDecline is returned when the user doesn't select the file.
	ErrUserDecline = errors.New("user exit the file selector without selecting a file")

	// ErrNotAvailable is return when the current OS isn't supported.
	ErrNotAvailable = errors.New("current OS not supported")
)

Functions

func ListenEvents

func ListenEvents(event event.Event)

ListenEvents must get all the events from Gio, in order to get the GioView. You must include that function where you listen for Gio events.

Similar as:

select { case e := <-window.Events():

		explorer.ListenEvents(e)
		switch e := e.(type) {
				(( ... your code ...  ))
		}
}

func ReadFile

func ReadFile(extensions ...string) (io.ReadCloser, error)

ReadFile shows the file selector, allowing the user to select a single file. Optionally, it's possible to define which file extensions is supported to be selected (such as `.jpg`, `.png`).

Example: ReadFile(".jpg", ".png") will only accept the selection of files with .jpg or .png extensions.

In some platforms the resulting `io.ReadCloser` is a `os.File`, but it's not a guarantee.

func WriteFile

func WriteFile(name string) (io.WriteCloser, error)

WriteFile opens the file selector, and writes the given content into some file, which the use can choose the location.

It's important to close the `io.WriteCloser`. In some platforms the file will be saved only when the writer is closer.

In some platforms the resulting `io.ReadCloser` is a `os.File`, but it's not a guarantee.

Types

This section is empty.

Jump to

Keyboard shortcuts

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