Products
  • Wolfram|One

    The definitive Wolfram Language and notebook experience

  • Mathematica

    The original technical computing environment

  • Wolfram Notebook Assistant + LLM Kit

    All-in-one AI assistance for your Wolfram experience

  • System Modeler
  • Wolfram Player
  • Finance Platform
  • Wolfram Engine
  • Enterprise Private Cloud
  • Application Server
  • Wolfram|Alpha Notebook Edition
  • Wolfram Cloud App
  • Wolfram Player App

More mobile apps

Core Technologies of Wolfram Products

  • Wolfram Language
  • Computable Data
  • Wolfram Notebooks
  • AI & Linguistic Understanding

Deployment Options

  • Wolfram Cloud
  • wolframscript
  • Wolfram Engine Community Edition
  • Wolfram LLM API
  • WSTPServer
  • Wolfram|Alpha APIs

From the Community

  • Function Repository
  • Community Paclet Repository
  • Example Repository
  • Neural Net Repository
  • Prompt Repository
  • Wolfram Demonstrations
  • Data Repository
  • Group & Organizational Licensing
  • All Products
Consulting & Solutions

We deliver solutions for the AI era—combining symbolic computation, data-driven insights and deep technical expertise

  • Data & Computational Intelligence
  • Model-Based Design
  • Algorithm Development
  • Wolfram|Alpha for Business
  • Blockchain Technology
  • Education Technology
  • Quantum Computation

WolframConsulting.com

Wolfram Solutions

  • Data Science
  • Artificial Intelligence
  • Biosciences
  • Healthcare Intelligence
  • Sustainable Energy
  • Control Systems
  • Enterprise Wolfram|Alpha
  • Blockchain Labs

More Wolfram Solutions

Wolfram Solutions For Education

  • Research Universities
  • Colleges & Teaching Universities
  • Junior & Community Colleges
  • High Schools
  • Educational Technology
  • Computer-Based Math

More Solutions for Education

  • Contact Us
Learning & Support

Get Started

  • Wolfram Language Introduction
  • Fast Intro for Programmers
  • Fast Intro for Math Students
  • Wolfram Language Documentation

More Learning

  • Highlighted Core Areas
  • Demonstrations
  • YouTube
  • Daily Study Groups
  • Wolfram Schools and Programs
  • Books

Grow Your Skills

  • Wolfram U

    Courses in computing, science, life and more

  • Community

    Learn, solve problems and share ideas.

  • Blog

    News, views and insights from Wolfram

  • Resources for

    Software Developers

Tech Support

  • Contact Us
  • Support FAQs
  • Support FAQs
  • Contact Us
Company
  • About Wolfram
  • Career Center
  • All Sites & Resources
  • Connect & Follow
  • Contact Us

Work with Us

  • Student Ambassador Initiative
  • Wolfram for Startups
  • Student Opportunities
  • Jobs Using Wolfram Language

Educational Programs for Adults

  • Summer School
  • Winter School

Educational Programs for Youth

  • Middle School Camp
  • High School Research Program
  • Computational Adventures

Read

  • Stephen Wolfram's Writings
  • Wolfram Blog
  • Wolfram Tech | Books
  • Wolfram Media
  • Complex Systems

Educational Resources

  • Wolfram MathWorld
  • Wolfram in STEM/STEAM
  • Wolfram Challenges
  • Wolfram Problem Generator

Wolfram Initiatives

  • Wolfram Science
  • Wolfram Foundation
  • History of Mathematics Project

Events

  • Stephen Wolfram Livestreams
  • Online & In-Person Events
  • Contact Us
  • Connect & Follow
Wolfram|Alpha
  • Your Account
  • User Portal
  • Wolfram Cloud
  • Products
    • Wolfram|One
    • Mathematica
    • Wolfram Notebook Assistant + LLM Kit
    • System Modeler
    • Wolfram Player
    • Finance Platform
    • Wolfram|Alpha Notebook Edition
    • Wolfram Engine
    • Enterprise Private Cloud
    • Application Server
    • Wolfram Cloud App
    • Wolfram Player App

    More mobile apps

    • Core Technologies
      • Wolfram Language
      • Computable Data
      • Wolfram Notebooks
      • AI & Linguistic Understanding
    • Deployment Options
      • Wolfram Cloud
      • wolframscript
      • Wolfram Engine Community Edition
      • Wolfram LLM API
      • WSTPServer
      • Wolfram|Alpha APIs
    • From the Community
      • Function Repository
      • Community Paclet Repository
      • Example Repository
      • Neural Net Repository
      • Prompt Repository
      • Wolfram Demonstrations
      • Data Repository
    • Group & Organizational Licensing
    • All Products
  • Consulting & Solutions

    We deliver solutions for the AI era—combining symbolic computation, data-driven insights and deep technical expertise

    WolframConsulting.com

    Wolfram Solutions

    • Data Science
    • Artificial Intelligence
    • Biosciences
    • Healthcare Intelligence
    • Sustainable Energy
    • Control Systems
    • Enterprise Wolfram|Alpha
    • Blockchain Labs

    More Wolfram Solutions

    Wolfram Solutions For Education

    • Research Universities
    • Colleges & Teaching Universities
    • Junior & Community Colleges
    • High Schools
    • Educational Technology
    • Computer-Based Math

    More Solutions for Education

    • Contact Us
  • Learning & Support

    Get Started

    • Wolfram Language Introduction
    • Fast Intro for Programmers
    • Fast Intro for Math Students
    • Wolfram Language Documentation

    Grow Your Skills

    • Wolfram U

      Courses in computing, science, life and more

    • Community

      Learn, solve problems and share ideas.

    • Blog

      News, views and insights from Wolfram

    • Resources for

      Software Developers
    • Tech Support
      • Contact Us
      • Support FAQs
    • More Learning
      • Highlighted Core Areas
      • Demonstrations
      • YouTube
      • Daily Study Groups
      • Wolfram Schools and Programs
      • Books
    • Support FAQs
    • Contact Us
  • Company
    • About Wolfram
    • Career Center
    • All Sites & Resources
    • Connect & Follow
    • Contact Us

    Work with Us

    • Student Ambassador Initiative
    • Wolfram for Startups
    • Student Opportunities
    • Jobs Using Wolfram Language

    Educational Programs for Adults

    • Summer School
    • Winter School

    Educational Programs for Youth

    • Middle School Camp
    • High School Research Program
    • Computational Adventures

    Read

    • Stephen Wolfram's Writings
    • Wolfram Blog
    • Wolfram Tech | Books
    • Wolfram Media
    • Complex Systems
    • Educational Resources
      • Wolfram MathWorld
      • Wolfram in STEM/STEAM
      • Wolfram Challenges
      • Wolfram Problem Generator
    • Wolfram Initiatives
      • Wolfram Science
      • Wolfram Foundation
      • History of Mathematics Project
    • Events
      • Stephen Wolfram Livestreams
      • Online & In-Person Events
    • Contact Us
    • Connect & Follow
  • Wolfram|Alpha
  • Wolfram Cloud
  • Your Account
  • User Portal
Wolfram Language & System Documentation Center
DefineInputStreamMethod
  • See Also
    • RemoveInputStreamMethod
  • Related Guides
    • Stream Methods
    • Low-Level File Operations
  • Tech Notes
    • Stream Methods
    • See Also
      • RemoveInputStreamMethod
    • Related Guides
      • Stream Methods
      • Low-Level File Operations
    • Tech Notes
      • Stream Methods

DefineInputStreamMethod["name",{"fname1"function1,"fname2"function2,… }]

defines a custom input stream method with the specified name, allowing the Wolfram Language to call the stream functions fnamei for opening and reading from an input stream.

Details and Options
Details and Options Details and Options
Examples  
Basic Examples  
Scope  
Neat Examples  
See Also
Tech Notes
Related Guides
History
Cite this Page
BUILT-IN SYMBOL
  • See Also
    • RemoveInputStreamMethod
  • Related Guides
    • Stream Methods
    • Low-Level File Operations
  • Tech Notes
    • Stream Methods
    • See Also
      • RemoveInputStreamMethod
    • Related Guides
      • Stream Methods
      • Low-Level File Operations
    • Tech Notes
      • Stream Methods

DefineInputStreamMethod

DefineInputStreamMethod["name",{"fname1"function1,"fname2"function2,… }]

defines a custom input stream method with the specified name, allowing the Wolfram Language to call the stream functions fnamei for opening and reading from an input stream.

Details and Options

  • An input stream method can provide a new source of bytes, a way to filter a stream of bytes, or a combination of both.
  • The following stream functions can be provided:
  • "NameTestFunction"whether a stream of the given name can be opened
    "ConstructorFunction"called when a new stream is opened
    "CloseFunction"close the stream and release its resources
    "ReadFunction"read bytes from the stream
    "EndOfFileQFunction"indicate whether the stream has no more input to read
    "WaitForInputFunction"wait until there is input to read
    "SeekFunction"reposition the point in the stream from which input is read
    "StreamPositionFunction"the current point in the stream from which input is read
    "StreamSizeFunction"the number of bytes that can be read from the stream
    "SeekableQFunction"indicate whether the stream method can reposition the point from which input is read
    "ErrorTextFunction"indicate whether there has been an error
    "ClearErrorFunction"clear the error indication
    "OptionChangesFunction"modify the options returned by Options[stream]
  • Only the "ConstructorFunction" must be supplied to DefineInputStreamMethod. Other functions have a default definition if a function is not provided.
  • Each InputStream opened with a stream method has a current state. This is where a stream method can store information such as a handle to the underlying stream resource, the current stream position, the latest error message, and other information needed by the stream method functions. The initial state expression is returned by "ConstructorFunction". Other functions take the current state as a parameter and return a new state value.
  • If a function returning a new state value is not provided, the default definition returns the given state unmodified.
  • Functions for opening and closing an input stream are:
  • NameParametersReturn Value
    "NameTestFunction"{streamname}True|False
    "ConstructorFunction"{streamname,caller,opts}{success,state}
    "CloseFunction"{state}ignored
  • "NameTestFunction" is needed when the stream is opened with Method->Automatic, and the Wolfram Language needs to choose a stream method to use based on streamname. A stream method will be used if its "NameTestFunction" returns True. If no "NameTestFunction" is provided, the default behavior is to return False.
  • When a stream is opened for reading, the "ConstructorFunction" is called. It opens a stream indicated by streamname, which could be a file name, URL, or other resource identification appropriate to the stream method. The caller argument is a symbol for issuing messages. The calling function, such as OpenRead, will complete its creation of an InputStream if success is True. The state is used as the initial value of the stream method's state.
  • "CloseFunction" is used for a stream st when Close[st] is called. Resources allocated in the "ConstructorFunction" should be deallocated here. The default definition does nothing.
  • Functions for reading from the stream include:
  • NameParametersReturn Value
    "ReadFunction"{state,n}{{byte1,...,byten},newstate}
    "EndOfFileQFunction"{state}{flag,newstate}
    "WaitForInputFunction"{state}{ignored,newstate}
  • "ReadFunction" is the essential function for reading from the stream. It takes an argument n and returns a list of n bytes, integers ranging from 0 to 255. Fewer bytes may be returned if the stream is at the end of file, or if there is an error while reading. In that case, "EndOfFileQFunction" and "ErrorTextFunction" are used to determine the cause. If no "ReadFunction" is provided, the default definition returns an empty list of bytes.
  • "EndOfFileQFunction" is used in the process of reading from the stream, and a stream method should typically provide this function. This function should return True when the last byte of the stream has been returned by the "ReadFunction". The default definition returns True.
  • "WaitForInputFunction" is used in the process of reading from a stream. This method is useful for stream methods that read from a source where input may be available intermittently, such as from a pipe to another process. In such a case, a stream method's "ReadFunction" should ensure that it never waits for input and only returns as many bytes as available; "WaitForInputFunction" is the place where it waits for input. The default definition does nothing.
  • Functions for reading and setting the stream size and position are as follows:
  • NameParametersReturn Value
    "StreamPositionFunction"{state}{position,newstate}
    "StreamSizeFunction"{state}{size,newstate}
    "SeekableQFunction"{state}{flag,newstate}
    "SeekFunction"{state,offset}{success,newstate}
  • "StreamPositionFunction" is used to support StreamPosition. The position result is an integer that specifies the position of the current point in the open stream. A position of -1 indicates that the stream position is unknown. The default definition returns a position of -1.
  • "StreamSizeFunction" is used in the process of reading from the stream. A stream method that provides this function with an accurate stream size may perform faster than a stream method that does not. The size result is an integer that specifies the total number of bytes in the stream, or -1 if the size is unknown. The default definition returns a size of -1.
  • "SeekableQFunction" is used to support SetStreamPosition. A stream method that provides a "SeekFunction" should provide a "SeekableQFunction" that returns True. The default definition returns False.
  • "SeekFunction" is used to support SetStreamPosition. If a stream method does not support setting the stream position, this function does not need to be provided, but "SeekableQFunction" should return False. This function is called with offset, which is either a non-negative integer indicating a byte position relative to the start of the stream, or Infinity indicating the position at the end of the stream. This function should return True to indicate that the seek succeeded.
  • Functions for handling errors are as follows:
  • NameParametersReturn Value
    "ErrorTextFunction"{state,nbytes}{result,newstate}
    "ClearErrorFunction"{state}{ignored,newstate}
  • "ErrorTextFunction" is used in the process of reading from the stream. It should return an error message String if there is an error condition and Null if there is no error. The Wolfram Language will call this function if other functions indicate failure, for example, if "ReadFunction" returns fewer bytes than requested and "EndOfFileQFunction" returns False. The default definition returns a result of Null.
  • "ClearErrorFunction" is called if "ErrorTextFunction" returned an error string and is called to clear the error state. After this, "ErrorTextFunction" should return Null until there is another error reading from the stream. The result of this function is ignored. It is recommended that a stream method providing an "ErrorTextFunction" should also provide a "ClearErrorFunction" definition.
  • "OptionChangesFunction" is used to edit the options for a stream st from the list returned by Options[st,Method]. For example, a stream method may take an option that includes a password or other piece of sensitive security data. By default, Options will return that setting. This function provides a way to remove that option field.
  • Function for changing options is as follows:
  • NameParametersReturn Value
    "OptionChangesFunction"{state,options}{newoptions,newstate}

Examples

open all close all

Basic Examples  (1)

Define a stream method that takes its input from a list of bytes, passed as a method option "Bytes":

Open a stream to a list of bytes, which could have come from anywhere:

Read from the stream:

Close the stream:

Scope  (1)

A stream method that does not define seek methods will work, but the kernel will need to use more memory to support certain operations. This shows that more and more bytes are read on successive read calls to fill a growing buffer:

By adding support for "SeekableQFunction", "StreamSize", and "SeekFunction", the read buffer remains the same size:

Neat Examples  (1)

Define an input stream method that opens a stream to a file inside a zip archive:

Open a stream to a text file inside a jar file:

Read the lines from it:

Close the stream and release its resources:

See Also

RemoveInputStreamMethod

Tech Notes

    ▪
  • Stream Methods

Related Guides

    ▪
  • Stream Methods
  • ▪
  • Low-Level File Operations

History

Introduced in 2012 (9.0)

Wolfram Research (2012), DefineInputStreamMethod, Wolfram Language function, https://reference.wolfram.com/language/ref/DefineInputStreamMethod.html.

Text

Wolfram Research (2012), DefineInputStreamMethod, Wolfram Language function, https://reference.wolfram.com/language/ref/DefineInputStreamMethod.html.

CMS

Wolfram Language. 2012. "DefineInputStreamMethod." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/DefineInputStreamMethod.html.

APA

Wolfram Language. (2012). DefineInputStreamMethod. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/DefineInputStreamMethod.html

BibTeX

@misc{reference.wolfram_2025_defineinputstreammethod, author="Wolfram Research", title="{DefineInputStreamMethod}", year="2012", howpublished="\url{https://reference.wolfram.com/language/ref/DefineInputStreamMethod.html}", note=[Accessed: 30-November-2025]}

BibLaTeX

@online{reference.wolfram_2025_defineinputstreammethod, organization={Wolfram Research}, title={DefineInputStreamMethod}, year={2012}, url={https://reference.wolfram.com/language/ref/DefineInputStreamMethod.html}, note=[Accessed: 30-November-2025]}

Top
Introduction for Programmers
Introductory Book
Wolfram Function Repository | Wolfram Data Repository | Wolfram Data Drop | Wolfram Language Products
Top
  • Products
  • Wolfram|One
  • Mathematica
  • Notebook Assistant + LLM Kit
  • System Modeler

  • Wolfram|Alpha Notebook Edition
  • Wolfram|Alpha Pro
  • Mobile Apps

  • Wolfram Player
  • Wolfram Engine

  • Volume & Site Licensing
  • Server Deployment Options
  • Consulting
  • Wolfram Consulting
  • Repositories
  • Data Repository
  • Function Repository
  • Community Paclet Repository
  • Neural Net Repository
  • Prompt Repository

  • Wolfram Language Example Repository
  • Notebook Archive
  • Wolfram GitHub
  • Learning
  • Wolfram U
  • Wolfram Language Documentation
  • Webinars & Training
  • Educational Programs

  • Wolfram Language Introduction
  • Fast Introduction for Programmers
  • Fast Introduction for Math Students
  • Books

  • Wolfram Community
  • Wolfram Blog
  • Public Resources
  • Wolfram|Alpha
  • Wolfram Problem Generator
  • Wolfram Challenges

  • Computer-Based Math
  • Computational Thinking
  • Computational Adventures

  • Demonstrations Project
  • Wolfram Data Drop
  • MathWorld
  • Wolfram Science
  • Wolfram Media Publishing
  • Customer Resources
  • Store
  • Product Downloads
  • User Portal
  • Your Account
  • Organization Access

  • Support FAQ
  • Contact Support
  • Company
  • About Wolfram
  • Careers
  • Contact
  • Events
Wolfram Community Wolfram Blog
Legal & Privacy Policy
WolframAlpha.com | WolframCloud.com
© 2025 Wolfram
© 2025 Wolfram | Legal & Privacy Policy |
English