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

  • Home
  • SEARCH
  • 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 121783
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T04:01:31+00:00 2026-05-11T04:01:31+00:00

I’ve been pouring over the format description and source code for the 7z archive

  • 0

I’ve been pouring over the format description and source code for the 7z archive format, but I’m still having trouble writing a valid container. I assume I can create an empty container… anyway here’s my start:

std::ofstream ofs(archivename.c_str(), std::ios::binary|std::ios::trunc);  Byte signature[6] = {'7', 'z', 0xBC, 0xAF, 0x27, 0x1C}; Byte major = 0; Byte minor = 3;  ofs.write((const char*)signature, 6); ofs.write((const char*)major, 1); ofs.write((const char*)minor, 1);  UInt64 offset = 0; UInt64 size = 0; UInt32 crc = 0;  ofs.write((const char*)offset, 4); ofs.write((const char*)size, 8); ofs.write((const char*)crc, 8); ofs.write((const char*)CrcCalc(0, 0), 8);  ofs.close(); 

I think my main problem is a lack of understanding of std::ofstream::write(). Byte is an ‘unsigned char’, UInt64 & UInt32 are both ‘unsigned long’.

UPDATE0: As everyone points out, it’d be a problem if I ran this on a big-endian machine. That’s not the case here. Per Fredrik Janssen, I should be casting the address of the non-arrays. I should also mention that CrcCalc() is a function in the LZMA SDK. Adding & helps a bit, it’s that first unsigned char[6] that’s having some problems.

UPDATE1: Working code to get an empty archive file below.

static void SetUInt32(Byte *p, UInt32 d) {   for (int i = 0; i < 4; i++, d >>= 8)     p[i] = (Byte)d; }  static void SetUInt64(Byte *p, UInt64 d) {   for (int i = 0; i < 8; i++, d >>= 8)     p[i] = (Byte)d; }  void make_7z_archive() {   CrcGenerateTable();    std::ofstream ofs(archivename.c_str(), std::ios::binary|std::ios::trunc);    Byte signature[6] = {'7', 'z', 0xBC, 0xAF, 0x27, 0x1C};   Byte major = 0;   Byte minor = 3;    ofs.write((const char*)signature, 6);   ofs.write((const char*)&major, 1);   ofs.write((const char*)&minor, 1);    UInt64 offset = 0;   UInt64 size = 0;   UInt32 crc = 0;    Byte buf[24];   SetUInt64(buf + 4, offset);   SetUInt64(buf + 12, size);   SetUInt32(buf + 20, crc);   SetUInt32(buf, CrcCalc(buf + 4, 20));    ofs.write((const char*)buf, 24);    ofs.close(); } 

NOTE: CrcGenerateTable() and CrcCalc() are from the LZMA SDK.

  • 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. 2026-05-11T04:01:31+00:00Added an answer on May 11, 2026 at 4:01 am

    don’t know the format of 7z, but I notice when you write down offset, size and crc that these will be written to the file in little-endian format (I assume you have a little-endian CPU).

    Edit: An probably worse, you are missing the & before major, minor, offset, size and crc, i.e. you are casting the actual values to a pointer.

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

Sidebar

Ask A Question

Stats

  • Questions 507k
  • Answers 507k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer This is usually called multi-tenancy. Here is a presentation or… May 16, 2026 at 3:58 pm
  • Editorial Team
    Editorial Team added an answer import time now = time.time() ... later = time.time() difference… May 16, 2026 at 3:58 pm
  • Editorial Team
    Editorial Team added an answer Use std::ofstream This is because we have to explicitly specify… May 16, 2026 at 3:58 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a jquery bug and I've been looking for hours now, I can't
Seemingly simple, but I cannot find anything relevant on the web. What is the
I want to count how many characters a certain string has in PHP, but
I'm looking for suggestions for debugging... If you view this site in Firefox or
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and

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.