Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:10421 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 79628 invoked by uid 1010); 13 Jun 2004 13:12:07 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 79594 invoked by uid 1007); 13 Jun 2004 13:12:06 -0000 Message-ID: <20040613131206.79593.qmail@pb1.pair.com> To: internals@lists.php.net Reply-To: "l0t3k" Date: Sun, 13 Jun 2004 09:12:06 -0400 Lines: 37 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1106 X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 X-Posted-By: 65.3.105.187 Subject: Pack function : a suggestion - allow array as second argument. From: cshmoove@bellsouth.net ("l0t3k") Scenario : i have an extension which requires an external binary (data) file. Since the extension has to be cross platform, the data file has to be built on the target platform to ensure that there are no endian issues. Therefore, i transform the file into a csv file of byte values, hoping to use Pack at the final stage of the build process to create a platform-endian file. The Problem Pack is written "vararg" style, which works great for a small set of values, but is a pain for larger sets of data. i know its possible to loop through my data and do a per-byte conversion, but my file is currently near 90K. Suggestion: Allow for an array as the second parameter. That way all i need to do is : $new_file = fopen($platform_file, "wb"); $lines = file($big_binary_file); foreach ($lines as $line) { $array_of_bytes_as_string = split(",", $line); $bin_string = pack("C*", $array_of_bytes_as_string); fwrite($new_file, $bin_string); } fclose($new_file); In Case You're Wondering: Why am i not doing this via C ? it is quite possible for parts of the total data set to change between releases of the extension. the file i want to convert is fairly static, but there are other data files which the extension user may customize, or that may need to be corrected. in that case, a simple PHP script can be run to create the binary file. No compiler or PHP build environment is necessary, and there is no need to wait for a new release of the extension. l0t3k