The loadBytes() function is used to read the contents of a file or URL and return it as an object containing the series of bytes. The bytes can then be accessed by using the “bytes” property of the object. The file must be present in the sketch directory to be accessed. This method can support file sizes up to 64MB.
This function is asynchronous, therefore it is recommended to be called in the preload() function to ensure that the function is executed before the other functions.
loadBytes(file, [callback], [errorCallback])
Parameters: This function accept three parameters as mentioned above and described below:
- file: It is a string that denotes the file path or URL from where the XML data has to be loaded.
- callback: It is a function that is called when this function executes successfully. The first argument for this function is the XML data loaded from the file. It is an optional parameter.
- errorCallback: It is a function that is called if there is any error in executing the function. The first argument for this function is the error response. It is an optional parameter.
Return Value: It returns an object which has the “bytes” property set to the bytes loaded from the file.
Below examples illustrate the loadBytes() function in p5.js:
- How to get the function name inside a function in PHP ?
- p5.js | str() function
- CSS | var() Function
- PHP | Ds\Map get() Function
- PHP | pow( ) Function
- PHP | ord() Function
- p5.js | hex() function
- CSS | url() Function
- PHP | exp() Function
- D3.js | d3.set.has() Function
- D3.js | d3.set.add() Function
- D3.js | d3.max() function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.