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 5961677
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:59:54+00:00 2026-05-22T18:59:54+00:00

I used Ruby to read an image file and save that into a string.

  • 0

I used Ruby to read an image file and save that into a string.

partial_image100 = File.read("image.tga")
partial_image99 = File.read("image.tga")
partial_image98 = File.read("image.tga")
...

I read those images at one end of a distributed system. In another system I want to do a Tail operation. The system receives just the images.

I have around a 100 partial images. I want to do a Tail operation, like this:

tail -c +19 image100 >> image99
tail -c +19 image99 >> image98
tail -c +19 image97 >> image96
...

Basically it just removes the first 18 bytes of the partial image and append what is left to the next image.

The problem is that this is slow. Calling 100 unix commands from Ruby is slow. I want to refactor this so that this happen in Ruby world. Just in memory. No files.

How can I do this in Ruby?

Thanks

edit:

The images are stored in a hash like this:

{"27"=>"\u0000\u0000\u0002\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u000E\u0001\xD0\a\xD0\a\u0018 \xFF\xFF\u0000\xFF\xFF\u0000\xFF\xFF\u0000\xFF\xFF\u0000\xFF\xFF\u0000\xFF\xFF\u0000\xFF\xFF\u0000\xFF\xFF\u0000\xFF\xFF\u0000\xFF\xFF\u0000\xFF\xFF\u0000\xFF\xFF\u0000\xFF\xFF\u0000\xFF\xFF\u0000\xFF\xFF\u0000\xFF\xFF\u0000\xFF\xFF\u0000\xFF\xFF\u0000\xFF\xFF\u0000\xFF\xFF\u0000\xFF\xFF\u0000\xFF\xFF\u0000\xFF\xFF\u0000\xFF\xFF\u0000\xFF\xFF\u0000\xFF\xFF\u0000\xFF\xFF\u0000\xFF\xFF\u0000\xFF\xFF\u0000\xFF\xFF\u0000\xFF\xFF\u0000\xFF\xFF\u0000\xFF\xFF\u0000\xFF\xFF\u0000\xFF\xFF\u0000\xFF\xFF\u0000\xFF\xFF\u0000\xFF\xFF\u0000\xFF\xFF\u0000\xFF\xFF\u0000\xFF\xFF\u0000\xFF\xFF...

EDIT:

You have all the relevant code here: https://gist.github.com/989563

There are two files. The code and a hash object encoded in json in a file. When you run the code there will be two image files created at /tmp

  • /tmp/image-tail-merger.tga – The output from the tail-merge algorithm
  • /tmp/image-/time/.tga – the output from the in-memory-tail algorithm

Currently the in-memory algorithm fails because the generated image is a Picasso.

If you manage to make the in-memory-algorithm generate the same image that the tail-merge algorithm do then you have succeeded.

EDIT:

I got it right finally!!!

Here is the code
https://gist.github.com/989563

  • 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-22T18:59:55+00:00Added an answer on May 22, 2026 at 6:59 pm

    You might try something like this

    image100 = "some image string"
    image99 = "some other image string"
    
    image99 += image100.slice(0,19)
    

    EDIT: In your specific example you could do this to iterate through the entire image

    (image_hash.size..1).each do i
      # Here we use slice to select everything *except* the first 19 bytes
      # Note: To select just the first 19 bytes we could do slice(0,19)
      #       To select just the last 19 bytes we could do slice(-19,19)
    
      # We then append this result to the next image down the line
      image_hash[i-1] += image_hash[i].slice(19,image_hash[i].size-19)
    end
    

    If you want to remove the “tailed” bits permanently you can use slice! to do an inline replace.

    Maybe a bit cleaner:

    # Strip the headers
    image_hash.each { |k,v| v.slice!(0,19) }
    
    # Append them together
    (image_hash.keys.sort).collect{ |i| image_hash[i] }.join
    

    EDIT: Working code example https://gist.github.com/989563

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

Sidebar

Related Questions

I have ruby build file that we used to read the assembly attributes that
is there are proper subversion client for ruby, that could be used to manage
I read in some Microsoft documentation that PHP, together with Ruby on Rails, is
Has anyone used Ruby/Rails with a Sales Logix database?
In Ruby, I'm used to using Enumerable#inject for going through a list or other
I used textmate to work with ruby code for over one year. Recently I
An idiom commonly used in OO languages like Python and Ruby is instantiating an
MVC is used a number of popular frameworks. To name just a few, Ruby
I have recently started a project in Ruby on Rails. I used to do
I'm new to the Ruby and Ruby on Rails world. I've read some guides,

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.