Skip to content

Added function to load from bytes array#31

Open
nb-programmer wants to merge 1 commit intoelectronoora:masterfrom
nb-programmer:master
Open

Added function to load from bytes array#31
nb-programmer wants to merge 1 commit intoelectronoora:masterfrom
nb-programmer:master

Conversation

@nb-programmer
Copy link

Added a function loadBuffer(buffer) to load Module data from an existing Buffer (useful for game engines that preload resources)

Still some things pending in this PR that I can't do without asking you:

  • The parse function of the tracker classes require the use of Uint8Array data, otherwise the function fails. Potential solution: Maybe a force cast can be done to the argument
  • The user has to set-up the 'format' and 'player' properties first before calling it. Maybe I can accept the format as argument to set it up
  • loadBuffer can be reused in load

I have also put these as TODO in the code that will need to be removed

@electronoora
Copy link
Owner

To forgo the need for the user to explicitly set the format and player properties before calling loadBuffer, we could maybe add an identify function to each of the format-specific player classes. Eg.

Screamtracker.prototype.identify(buffer)

which would return a boolean value depending on whether the contents of the buffer look like a S3M module - probably just by checking the file signature.

loadBuffer could then call identify for each format-specific class to autodetect the format contained within the buffer, and set the format and player properties accordingly.

This would probably be a more robust way for detecting the file type also for load as currently it just makes a guess based on the provided URL. One advantage with the current method is, however, that it can be done already before the XHR.

@nb-programmer
Copy link
Author

The identify function could be useful, but I feel relying on auto-detection for basically user-supplied data is a bad idea, as there could be false detections.
Perhaps the format argument can be made optional. If it is set, just assign the correct tracker class instance. Maybe another argument to prevent replacing the player property. If not set, we can try and guess using the identify methods

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants