intro.bbdoc 1.8 KB

123456789101112131415161718192021222324252627282930313233343536
  1. Streams are used to read or write data in a sequential manner.
  2. BlitzMax supports many kinds of streams, including standard file streams
  3. (for reading and writing to files), #{bank streams} (for reading and writing to banks) and
  4. #{endian streams} (for swapping the byte order of stream data).
  5. Streams are usually created using #OpenStream, #ReadStream or #WriteStream. However,
  6. some kinds of streams provide their own methods for creating streams. For example, banks
  7. streams are created with the #CreateBankStream command.
  8. #OpenStream, #ReadStream and #WriteStream all require a %url parameter, which is used to
  9. 'locate' the stream. A url is usually a string value.
  10. If the url contains the string "::", then a stream %protocol is being specified. If not,
  11. then the url is assumed to be a simple filename.
  12. External modules can add their own stream protocols to the system, allowing you to use streams
  13. for a wide variety of purposes. For example, the "incbin::" protocol allows you to read data
  14. from a binary file that has been embedded in an application using the #Incbin command.
  15. Other protocols include "http::" for reading and writing data over a network, and
  16. "littleendian::" and "bigendian::" for swapping the byte order of streams.
  17. To write to a stream, use one of the 'Write' style commands, such as #WriteByte.
  18. To read from a stream, use one of the 'Read' style commands, such as #ReadByte.
  19. Some kinds of streams (for example, file streams and bank streams) support %{random access}.
  20. This means that you can modify where in the stream the next read or write is to occur using
  21. the #SeekStream command. You can also tell where you are in such streams using the
  22. #StreamPos command.
  23. When you are finished with a stream, you should always close it using #CloseStream.
  24. Failure to do so may result in a resource leak, or prevent the stream from successfully
  25. opening in future.