Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6870585
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:42:05+00:00 2026-05-27T03:42:05+00:00

I read buffer of data from somewhere to bytearray . Now, I want to

  • 0

I read buffer of data from somewhere to bytearray. Now, I want to work with this data using stream-like interface (i.e. read, seek etc.)

Can I just wrap my bytearray with io.BytesIO?

mybytearray = bytearray(...)
stream = io.BytesIO(mybytearray)

My fear here is BytesIO copies data of mybytearray, but I don’t want it – since buffer is very big. I don’t want copies, I want the stream to work on original data and can modify it too. What can be done?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T03:42:05+00:00Added an answer on May 27, 2026 at 3:42 am

    BytesIO manages its own memory and will copy a buffer used to initialize it. You could encapsulate your bytearray in a file-like class. Or you can go the other way, letting the BytesIO object handle memory allocation. Then you can get a view of the buffer that can be modified by index and slice, but you can’t re-size the buffer while the view exists:

    >>> f = io.BytesIO(b'abc')
    >>> view = f.getbuffer()
    
    >>> view[:] = b'def'
    >>> f.getvalue()
    b'def'
    
    >>> view[3] = b'g'
    IndexError: index out of bounds
    
    >>> f.seek(0, 2)
    >>> f.write(b'g')
    BufferError: Existing exports of data: object cannot be re-sized
    
    >>> del view
    >>> f.write(b'g')
    >>> f.getvalue()
    b'defg'
    

    Edit:

    See issue 22003, BytesIO copy-on-write. The latest patch (cow6) supports copy-on-write for bytes only.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to store some binary data obtained from read() in my buffer using
I read the input buffer from a console application (CMD) like this: var pBuffer
When reading normally from an SslStream using the Read(byte[] buffer, int offset, int count)
EXACT DUPLICATE of How to read XML data from a URL by using vb.NET
I am trying to read in data from an input stream, but if the
I am using HttpWebResponse.GetResponseStream to access an internet radio stream, and want to read
I am using async_read_some to read data from a port that is saved in
I'm using RXTX to read data from a serial port. The reading is done
I need to read a massive amount of data into a buffer (about 20gig).
How does read(buffer, offset, length) actually work, if i pass the length to read

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.