|
| 1 | +// Copyright (C) 2015-2016 IBM Corporation and Others. All Rights Reserved. |
| 2 | + |
| 3 | +// Install by fetching ICU source tarball |
| 4 | +// This will only work for little endian systems, but will work for ancient ICU (back to v50) |
| 5 | + |
| 6 | +const fs = require('fs') |
| 7 | +const { URL } = require('url') |
| 8 | +const process = require('process') |
| 9 | +const myFetch = require('./myFetch') |
| 10 | +const yauzl = require('yauzl') |
| 11 | + |
| 12 | +module.exports = async function installFromGithub (fullIcu, advice) { |
| 13 | + const { icudat, icuend } = fullIcu |
| 14 | + if (fs.existsSync(icudat)) { |
| 15 | + console.log(` √ ${icudat} (exists)`) |
| 16 | + return |
| 17 | + } |
| 18 | + |
| 19 | + // Example URL: |
| 20 | + // https://github.com/unicode-org/icu/releases/download/release-51-3/icu4c-51_3-src.zip |
| 21 | + const _baseUrl = process.env.FULL_ICU_BASEURL || 'https://github.com/unicode-org/icu/releases/' |
| 22 | + const baseUrl = new URL(_baseUrl) |
| 23 | + const versionsAsHyphen = fullIcu.icuver.replace(/\./g, '-') |
| 24 | + // ICU v67/v68 use "68.1" and "67.1" in the filename instead of 68_1 and 69_1 |
| 25 | + // https://unicode-org.atlassian.net/browse/ICU-21764 |
| 26 | + // Can remove this conditional if the files are updated later. |
| 27 | + const versionsAsUnderscore = (fullIcu.icumaj >= 69) ? fullIcu.icuver.replace(/\./g, '_') : fullIcu.icuver |
| 28 | + const tag = `release-${versionsAsHyphen}` |
| 29 | + const file = `icu4c-${versionsAsUnderscore}-data-bin-${icuend}.zip` |
| 30 | + const fullUrl = new URL(`./download/${tag}/${file}`, baseUrl) |
| 31 | + console.log(fullUrl.toString()) |
| 32 | + const [srcZip, tmpd] = await myFetch(fullUrl) |
| 33 | + |
| 34 | + console.log(srcZip, tmpd) |
| 35 | + |
| 36 | + // now, unpack it |
| 37 | + console.log(`Looking for ${icudat}`) |
| 38 | + return new Promise((resolve, reject) => |
| 39 | + yauzl.open(srcZip, { lazyEntries: true }, (err, zipfile) => { |
| 40 | + if (err) return reject(err) |
| 41 | + zipfile.readEntry() |
| 42 | + zipfile.on('end', () => reject(Error(`Not found in zipfile: ${icudat}`))) |
| 43 | + zipfile.on('entry', (entry) => { |
| 44 | + if (entry.fileName.endsWith('/')) { |
| 45 | + zipfile.readEntry() |
| 46 | + } else if (entry.fileName.endsWith(icudat) || entry.fileName.endsWith('/' + icudat)) { |
| 47 | + console.log('found ' + entry.fileName) |
| 48 | + zipfile.openReadStream(entry, (err, readStream) => { |
| 49 | + if (err) return reject(err) |
| 50 | + readStream.on('end', () => zipfile.readEntry()) |
| 51 | + const pipeOut = fs.createWriteStream(icudat) |
| 52 | + readStream.pipe(pipeOut) |
| 53 | + console.log(` √ ${icudat} (from ICU binary data tarball)`) |
| 54 | + return resolve() |
| 55 | + }) |
| 56 | + } else { |
| 57 | + zipfile.readEntry() |
| 58 | + } |
| 59 | + }) |
| 60 | + })) |
| 61 | +} |
0 commit comments