Skip to content

Commit

Permalink
use \r\n for windows executable
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelzw committed Nov 28, 2024
1 parent 31ccdbf commit 06e4c73
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
15 changes: 11 additions & 4 deletions src/pack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,12 @@ async fn create_self_extracting_executable(
target: &Path,
platform: Platform,
) -> Result<()> {
let line_ending = if platform.is_windows() {
b"\r\n".to_vec()
} else {
b"\n".to_vec()
};

let archive = Builder::new(Vec::new());

let compressor = write_archive(archive, input_dir).await?;
Expand Down Expand Up @@ -410,20 +416,21 @@ async fn create_self_extracting_executable(
.map_err(|e| anyhow!("could not create final executable file: {}", e))?;

final_executable.write_all(header.as_bytes()).await?;
final_executable.write_all(b"\n").await?; // Add a newline after the header
final_executable.write_all(&line_ending).await?; // Add a newline after the header

// Encode the archive to base64
let archive_base64 = STANDARD.encode(&compressor);
final_executable
.write_all(archive_base64.as_bytes())
.await?;

final_executable.write_all(b"\n").await?;
final_executable.write_all(&line_ending).await?;
if platform.is_windows() {
final_executable.write_all(b"__END_ARCHIVE__\n").await?;
final_executable.write_all(b"__END_ARCHIVE__").await?;
} else {
final_executable.write_all(b"@@END_ARCHIVE@@\n").await?;
final_executable.write_all(b"@@END_ARCHIVE@@").await?;
}
final_executable.write_all(&line_ending).await?;

// Encode the executable to base64
let executable_base64 = STANDARD.encode(&executable_bytes);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
source: tests/integration_test.rs
assertion_line: 358
assertion_line: 366
expression: "&sha256_digest"
snapshot_kind: text
---
7D564558F9576FACF4BF9188CCE0B2F8BD98C5E52A8456DE4F06378BEF11BE27
D651688B08263EA415C95AF1298D337088953CD260BFFC1AB287D75E2F467D2A

0 comments on commit 06e4c73

Please sign in to comment.