Emojicode Documentation 1.0 beta 2

Class πŸ“„

The πŸ“„ class allows you to read and write to files.

It provides several class methods which are shortcuts to reading and writing. They operate always on the whole file and reading can be very inefficient using these shortcuts when working with big files, because they will read the whole file into memory.

You must close files openend with πŸ“ and πŸ“œ appropriately with πŸ™… when they are no longer needed.

Initializers

πŸ†•β–ΆοΈπŸ“

 πŸ†•β–ΆοΈπŸ“ πŸš¨πŸš§πŸ”Έβ†•  path πŸ”‘ Β πŸš§πŸš§πŸ”Έβ†•

Opens the file at the given path for writing. The file pointer is set to the beginning of the file and the file is truncated to zero length or created.

You cannot read from a file opened with this initializer.

πŸ†•β–ΆοΈπŸ“œ

 πŸ†•β–ΆοΈπŸ“œ πŸš¨πŸš§πŸ”Έβ†•  path πŸ”‘ Β πŸš§πŸš§πŸ”Έβ†•

Opens the file at the given path for reading. The file pointer is set to the beginning of the file.

You cannot write to a file opened with this initializer.

Methods

βœβ—οΈ

❗️ ✏  data πŸ“‡ Β πŸš§πŸš§πŸ”Έβ†•

Write the data at the current file pointer position.

πŸ““β—οΈ

❗️ πŸ““  bytesToRead πŸ”’ ➑️ πŸ“‡Β πŸš§πŸš§πŸ”Έβ†•

Reads as many bytes as specified from the file pointer position.

Keep in mind that a byte is not equal to one character!

πŸ”šβ—οΈ

❗️ πŸ”š 

Seeks the file pointer to the end of the file.

πŸ”›β—οΈ

❗️ πŸ”›  position πŸ”’ 

Seeks the file pointer to the given position.

πŸ’§β—οΈ

❗️ πŸ’§ 

Causes any buffered unwritten data to be written to the file.

πŸšͺ❗️

❗️ πŸšͺ 

Closes the file. Reading or writing thereafter is undefined behavior.

deinit❗️

❗️ deinit 

Type Methods

πŸ“»

πŸ‡β—οΈ πŸ“»  path πŸ”‘  data πŸ“‡ Β πŸš§πŸš§πŸ”Έβ†•

This class method tries to write the given πŸ“‡ to the given path. If the file already exists, it will be overwritten.

πŸ“‡

πŸ‡β—οΈ πŸ“‡  path πŸ”‘ ➑️ πŸ“‡Β πŸš§πŸš§πŸ”Έβ†•

This class method tries to read the file at given path path and returns a πŸ“‡ object representing its content on success. On failure an error is returned.