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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:26:21+00:00 2026-06-15T23:26:21+00:00

Since converting my code to read resources from an archive, i have noticed a

  • 0

Since converting my code to read resources from an archive, i have noticed a small drop in the performance of my application. How would i improve the following code to help to boost the performance back to as it was when using a flat file system or as close to as possible.

class Resource
{
    private static readonly string ResourcePath = AppDomain.CurrentDomain.BaseDirectory + "resources.pak";
    private const string ResourcePassword = "0ORzjHcFxV0QXTuOizu0";

    private static ZipFile Read(string filepath, string password = null)
    {
        var file = ZipFile.Read(filepath);
        file.Password = password;
        return file;
    }

    internal static List<string> GetFiles(string haystack, string needle = "*")
    {
        var resource = Read(ResourcePath, ResourcePassword).SelectEntries(needle, haystack);
        return resource.Select(filepath => filepath.ToString().Replace("ZipEntry::", "")).ToList();
    }

    internal static MemoryStream ReadFile(string filepath)
    {
        var file = Read(ResourcePath, ResourcePassword);
        var stream = new MemoryStream();
        file[filepath].Extract(stream);
        return stream;
    }

    internal static ImageSource StreamImage(string filepath)
    {
        var getFile = Resource.ReadFile(filepath);
        var imageSource = new BitmapImage();
        imageSource.BeginInit();
        imageSource.StreamSource = getFile;
        imageSource.EndInit();
        return imageSource;
    }

    internal static int[] ImageSize(string filepath)
    {
        int[] sizeValues = {0, 0};
        var readImage = Resource.ReadFile(filepath);
        var image = new BitmapImage();
        image.BeginInit();
        image.StreamSource = readImage;
        image.EndInit();
        sizeValues[0] = image.PixelWidth;
        sizeValues[1] = image.PixelHeight;
        return sizeValues;
    }

}

Please note that i have removed the error checking to keep the code short and to the point.

  • 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-06-15T23:26:22+00:00Added an answer on June 15, 2026 at 11:26 pm

    What do you mean by a drop in performance? I imagine you mean responsiveness? This would probably be because you are unpacking these resources on the main thread. Move this work to a background thread.

    Here is an example for .Net 4.5, using async / await. (untested)

    class Resource
    {
        private static readonly string ResourcePath = AppDomain.CurrentDomain.BaseDirectory + "resources.pak";
        private const string ResourcePassword = "0ORzjHcFxV0QXTuOizu0";
    
        private static ZipFile Read(string filepath, string password = null)
        {
            var file = ZipFile.Read(filepath);
            file.Password = password;
            return file;
        }
    
        internal static List<string> GetFiles(string haystack, string needle = "*")
        {
            var resource = Read(ResourcePath, ResourcePassword).SelectEntries(needle, haystack);
            return resource.Select(filepath => filepath.ToString().Replace("ZipEntry::", "")).ToList();
        }
    
        internal static Task<MemoryStream> ReadFile(string filepath)
        {
            return Task.Run(() =>
                {
                    var file = Read(ResourcePath, ResourcePassword);
                    var stream = new MemoryStream();
                    file[filepath].Extract(stream);
                    return stream;
                });
        }
    
        internal async static Task<ImageSource> StreamImage(string filepath)
        {
            var imageSource = new BitmapImage();
            imageSource.BeginInit();
            imageSource.StreamSource = await ReadFile(filepath);
            imageSource.EndInit();
            return imageSource;
        }
    
        internal async static Task<int[]> ImageSize(string filepath)
        {
            int[] sizeValues = { 0, 0 };
            var image = new BitmapImage();
            image.BeginInit();
            image.StreamSource = await ReadFile(filepath);
            image.EndInit();
            sizeValues[0] = image.PixelWidth;
            sizeValues[1] = image.PixelHeight;
            return sizeValues;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Since I'm more comfortable using Eclipse, I thought I'd try converting my project from
I'm working on converting a bit of code to SSE, and while I have
I'm converting my fields class read functions into one template function. I have field
I have written a code that solves MST using Prim method. I read that
I have this code for converting a byte[] to float[] . public float[] ConvertByteToFloat(byte[]
I have to do read an Large InputStream comming from a URL. I loaded
I've written some code in C for converting strings passed from VBA, when the
Since converting my project to ARC, it seems the analyzer is a bit in
I need help converting eregi_replace to preg_replace (since in PHP5 it's depreciated): function makeClickableLinks($text)
I am having trouble converting a value in a string array to int since

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.