Skip to content

Commit 1085271

Browse files
committed
perf: gzip compress binaries for faster downloads (v0.2.9)
1 parent fe33502 commit 1085271

4 files changed

Lines changed: 49 additions & 30 deletions

File tree

.github/workflows/release.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,21 +39,23 @@ jobs:
3939
cd packages/core
4040
pyinstaller --onefile --name thoth-core thoth_core/cli.py
4141
42-
- name: Rename binary (Unix)
42+
- name: Rename and compress binary (Unix)
4343
if: matrix.os != 'windows-latest'
4444
run: |
4545
mv packages/core/dist/thoth-core packages/core/dist/thoth-core-${{ matrix.target }}
46+
gzip -9 packages/core/dist/thoth-core-${{ matrix.target }}
4647
47-
- name: Rename binary (Windows)
48+
- name: Rename and compress binary (Windows)
4849
if: matrix.os == 'windows-latest'
4950
run: |
5051
mv packages/core/dist/thoth-core.exe packages/core/dist/thoth-core-${{ matrix.target }}.exe
52+
gzip -9 packages/core/dist/thoth-core-${{ matrix.target }}.exe
5153
5254
- name: Upload artifact
5355
uses: actions/upload-artifact@v4
5456
with:
5557
name: thoth-core-${{ matrix.target }}
56-
path: packages/core/dist/thoth-core-${{ matrix.target }}*
58+
path: packages/core/dist/thoth-core-${{ matrix.target }}*.gz
5759

5860
release:
5961
name: Create Release

packages/cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "thoth-cli",
3-
"version": "0.2.8",
3+
"version": "0.2.9",
44
"description": "𓅝 Astrological calculations from the command line. Swiss Ephemeris precision. Built for humans and agents.",
55
"author": "AKLO <aklo@aklolabs.com>",
66
"license": "MIT",

packages/cli/scripts/postinstall.js

Lines changed: 41 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,26 @@
11
#!/usr/bin/env node
22
/**
3-
* Postinstall script - downloads the correct thoth-core binary
3+
* Postinstall script - downloads and decompresses the correct thoth-core binary
44
* 𓅝
55
*/
66

77
import { platform, arch } from 'os';
88
import { join, dirname } from 'path';
9-
import { existsSync, mkdirSync, createWriteStream, chmodSync, statSync } from 'fs';
9+
import { existsSync, mkdirSync, createWriteStream, chmodSync, statSync, unlinkSync } from 'fs';
10+
import { createGunzip } from 'zlib';
11+
import { pipeline } from 'stream/promises';
1012
import { fileURLToPath } from 'url';
1113
import https from 'https';
1214

1315
const __dirname = dirname(fileURLToPath(import.meta.url));
1416

15-
const VERSION = '0.2.7';
17+
const VERSION = '0.2.9';
1618
const REPO = 'aklo360/thoth-cli';
17-
const BASE_URL = `https://github.com/${REPO}/releases/download/v${VERSION}`;
19+
20+
// Use jsDelivr CDN for faster downloads (mirrors GitHub releases)
21+
const CDN_URL = `https://cdn.jsdelivr.net/gh/${REPO}@v${VERSION}/releases`;
22+
// Fallback to GitHub releases directly
23+
const GITHUB_URL = `https://github.com/${REPO}/releases/download/v${VERSION}`;
1824

1925
function getPlatformKey() {
2026
const p = platform();
@@ -38,14 +44,12 @@ function getBinaryName() {
3844
return platform() === 'win32' ? 'thoth-core.exe' : 'thoth-core';
3945
}
4046

41-
async function download(url, dest) {
47+
function download(url) {
4248
return new Promise((resolve, reject) => {
43-
const file = createWriteStream(dest);
44-
4549
https.get(url, (response) => {
4650
// Handle redirects
4751
if (response.statusCode === 302 || response.statusCode === 301) {
48-
download(response.headers.location, dest).then(resolve).catch(reject);
52+
download(response.headers.location).then(resolve).catch(reject);
4953
return;
5054
}
5155

@@ -54,15 +58,19 @@ async function download(url, dest) {
5458
return;
5559
}
5660

57-
response.pipe(file);
58-
file.on('finish', () => {
59-
file.close();
60-
resolve();
61-
});
61+
resolve(response);
6262
}).on('error', reject);
6363
});
6464
}
6565

66+
async function downloadAndDecompress(url, dest) {
67+
const response = await download(url);
68+
const gunzip = createGunzip();
69+
const fileStream = createWriteStream(dest);
70+
71+
await pipeline(response, gunzip, fileStream);
72+
}
73+
6674
async function main() {
6775
const platformKey = getPlatformKey();
6876
const binaryName = getBinaryName();
@@ -72,34 +80,43 @@ async function main() {
7280
// Skip if binary already exists AND has content
7381
if (existsSync(binaryPath)) {
7482
const stats = statSync(binaryPath);
75-
if (stats.size > 0) {
76-
console.log(`✓ thoth-core binary already exists`);
83+
if (stats.size > 1000) { // Real binary is ~18MB, placeholder is 0
84+
console.log(`✓ thoth-core binary already exists (${(stats.size / 1024 / 1024).toFixed(1)}MB)`);
7785
return;
7886
}
79-
console.log(`Found empty placeholder, downloading actual binary...`);
87+
console.log(`Found placeholder, downloading actual binary...`);
88+
unlinkSync(binaryPath); // Remove placeholder
8089
}
8190

82-
console.log(`Downloading thoth-core for ${platformKey}...`);
83-
8491
// Create bin directory
8592
mkdirSync(binDir, { recursive: true });
8693

87-
// Download binary
88-
const url = `${BASE_URL}/thoth-core-${platformKey}${platform() === 'win32' ? '.exe' : ''}`;
94+
// Compressed filename
95+
const compressedName = `thoth-core-${platformKey}${platform() === 'win32' ? '.exe' : ''}.gz`;
96+
97+
// Try GitHub releases (jsDelivr doesn't serve release assets directly)
98+
const url = `${GITHUB_URL}/${compressedName}`;
99+
100+
console.log(`Downloading thoth-core for ${platformKey}...`);
101+
console.log(` From: ${url}`);
102+
103+
const startTime = Date.now();
89104

90105
try {
91-
await download(url, binaryPath);
106+
await downloadAndDecompress(url, binaryPath);
92107

93108
// Make executable on Unix
94109
if (platform() !== 'win32') {
95110
chmodSync(binaryPath, 0o755);
96111
}
97112

98-
console.log(`✓ Downloaded thoth-core to ${binaryPath}`);
113+
const stats = statSync(binaryPath);
114+
const elapsed = ((Date.now() - startTime) / 1000).toFixed(1);
115+
console.log(`✓ Downloaded and decompressed (${(stats.size / 1024 / 1024).toFixed(1)}MB) in ${elapsed}s`);
99116
} catch (error) {
100117
console.warn(`⚠ Could not download binary: ${error.message}`);
101-
console.warn(` You can run in development mode with Python installed.`);
102-
console.warn(` Install thoth-core: pip install thoth-core`);
118+
console.warn(` You may need to install thoth-core manually.`);
119+
console.warn(` Or install via: pip install thoth-core`);
103120
}
104121
}
105122

packages/cli/src/bin.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Examples:
3535
thoth progressions --natal-date 1991-07-08 --natal-time 14:06 --city "New York" --target-date 2026-03-01
3636
thoth moon
3737
thoth ephemeris --body pluto`)
38-
.version('0.2.8');
38+
.version('0.2.9');
3939

4040
// Chart command
4141
program
@@ -725,7 +725,7 @@ program
725725

726726
// Banner
727727
console.log(chalk.dim(''));
728-
console.log(chalk.yellow(' 𓅝') + chalk.dim(' thoth-cli v0.2.8'));
728+
console.log(chalk.yellow(' 𓅝') + chalk.dim(' thoth-cli v0.2.9'));
729729
console.log(chalk.dim(''));
730730

731731
program.parse();

0 commit comments

Comments
 (0)