Task 328: .JL File Format

Task 328: .JL File Format

File Format Specifications for .JL

The .JL file format is the standard extension for source code files written in the Julia programming language. It is a plain text file format containing Julia code, typically encoded in UTF-8. There is no binary structure or header; it follows the syntax and semantics defined by the Julia language. The full specifications can be found in the official Julia documentation at https://docs.julialang.org/en/v1/.

  1. List of all the properties of this file format intrinsic to its file system:
  • File name (including the .jl extension)
  • File size (in bytes)
  • Creation time (timestamp when the file was created)
  • Modification time (timestamp when the file was last modified)
  • Access time (timestamp when the file was last accessed)
  • Permissions (read, write, execute bits for owner, group, and others)
  • Owner user ID (UID)
  • Group ID (GID)
  • File type (typically "regular file" for .jl files)

These properties are standard file system metadata and not unique to the .jl format, but they are intrinsic to how the file is managed in the file system. Note that some properties (e.g., creation time) may not be available on all operating systems or file systems.

  1. Two direct download links for files of format .JL:
  1. Ghost blog embedded HTML JavaScript for drag-and-drop .JL file dump:
Drag and Drop .JL File Analyzer
Drag and drop a .JL file here

This HTML can be embedded in a Ghost blog post or used standalone. It allows dragging and dropping a .JL file and dumps the available properties to the screen (browser File API limits access to some file system properties like permissions or UID).

  1. Python class for .JL files:
import os
import time
import stat

class JLFileHandler:
    def __init__(self, filepath):
        self.filepath = filepath
        self.content = None

    def read(self):
        """Read (decode) the file content as UTF-8 text."""
        with open(self.filepath, 'r', encoding='utf-8') as f:
            self.content = f.read()
        return self.content

    def write(self, new_filepath, content=None):
        """Write content to a new .JL file."""
        if content is None:
            content = self.content if self.content else ''
        with open(new_filepath, 'w', encoding='utf-8') as f:
            f.write(content)

    def print_properties(self):
        """Print all file system properties."""
        if not os.path.exists(self.filepath):
            print("File does not exist.")
            return

        stats = os.stat(self.filepath)
        print(f"File name: {os.path.basename(self.filepath)}")
        print(f"File size: {stats.st_size} bytes")
        print(f"Creation time: {time.ctime(stats.st_ctime)}")
        print(f"Modification time: {time.ctime(stats.st_mtime)}")
        print(f"Access time: {time.ctime(stats.st_atime)}")
        print(f"Permissions: {oct(stats.st_mode)[-3:]}")
        print(f"Owner UID: {stats.st_uid}")
        print(f"Group GID: {stats.st_gid}")
        print(f"File type: {'regular file' if stat.S_ISREG(stats.st_mode) else 'other'}")

# Example usage:
# handler = JLFileHandler('example.jl')
# handler.read()
# handler.print_properties()
# handler.write('new_example.jl', 'println("Hello, Julia!")')
  1. Java class for .JL files:
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.attribute.BasicFileAttributes;
import java.nio.file.attribute.PosixFileAttributes;
import java.nio.file.attribute.PosixFilePermissions;
import java.text.SimpleDateFormat;

public class JLFileHandler {
    private String filepath;
    private String content;

    public JLFileHandler(String filepath) {
        this.filepath = filepath;
        this.content = null;
    }

    public String read() throws IOException {
        // Read (decode) as UTF-8 text
        Path path = Paths.get(filepath);
        byte[] bytes = Files.readAllBytes(path);
        content = new String(bytes, StandardCharsets.UTF_8);
        return content;
    }

    public void write(String newFilepath, String newContent) throws IOException {
        if (newContent == null) {
            newContent = content != null ? content : "";
        }
        try (BufferedWriter writer = new BufferedWriter(new FileWriter(newFilepath))) {
            writer.write(newContent);
        }
    }

    public void printProperties() throws IOException {
        Path path = Paths.get(filepath);
        if (!Files.exists(path)) {
            System.out.println("File does not exist.");
            return;
        }

        BasicFileAttributes attrs = Files.readAttributes(path, BasicFileAttributes.class);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        System.out.println("File name: " + path.getFileName());
        System.out.println("File size: " + attrs.size() + " bytes");
        System.out.println("Creation time: " + sdf.format(attrs.creationTime().toMillis()));
        System.out.println("Modification time: " + sdf.format(attrs.lastModifiedTime().toMillis()));
        System.out.println("Access time: " + sdf.format(attrs.lastAccessTime().toMillis()));

        if (System.getProperty("os.name").startsWith("Windows")) {
            System.out.println("Permissions: Not directly available on Windows");
            System.out.println("Owner UID: Not applicable");
            System.out.println("Group GID: Not applicable");
        } else {
            PosixFileAttributes posixAttrs = Files.readAttributes(path, PosixFileAttributes.class);
            System.out.println("Permissions: " + PosixFilePermissions.toString(posixAttrs.permissions()));
            System.out.println("Owner UID: " + posixAttrs.owner().getName());  // Name instead of UID
            System.out.println("Group GID: " + posixAttrs.group().getName());  // Name instead of GID
        }
        System.out.println("File type: " + (attrs.isRegularFile() ? "regular file" : "other"));
    }

    // Example usage:
    // public static void main(String[] args) throws IOException {
    //     JLFileHandler handler = new JLFileHandler("example.jl");
    //     handler.read();
    //     handler.printProperties();
    //     handler.write("new_example.jl", "println(\"Hello, Julia!\")");
    // }
}
  1. JavaScript class for .JL files (Node.js, as browser can't access full file system properties):
const fs = require('fs');
const path = require('path');

class JLFileHandler {
    constructor(filepath) {
        this.filepath = filepath;
        this.content = null;
    }

    read() {
        // Read (decode) as UTF-8 text
        this.content = fs.readFileSync(this.filepath, 'utf-8');
        return this.content;
    }

    write(newFilepath, content = null) {
        if (content === null) {
            content = this.content || '';
        }
        fs.writeFileSync(newFilepath, content, 'utf-8');
    }

    printProperties() {
        if (!fs.existsSync(this.filepath)) {
            console.log('File does not exist.');
            return;
        }

        const stats = fs.statSync(this.filepath);
        console.log(`File name: ${path.basename(this.filepath)}`);
        console.log(`File size: ${stats.size} bytes`);
        console.log(`Creation time: ${stats.birthtime.toString()}`);
        console.log(`Modification time: ${stats.mtime.toString()}`);
        console.log(`Access time: ${stats.atime.toString()}`);
        console.log(`Permissions: ${stats.mode.toString(8).slice(-3)}`);
        console.log(`Owner UID: ${stats.uid}`);
        console.log(`Group GID: ${stats.gid}`);
        console.log(`File type: ${stats.isFile() ? 'regular file' : 'other'}`);
    }
}

// Example usage:
// const handler = new JLFileHandler('example.jl');
// handler.read();
// handler.printProperties();
// handler.write('new_example.jl', 'println("Hello, Julia!")');
  1. C "class" for .JL files (using struct and functions, as C has no classes):
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <time.h>
#include <unistd.h>
#include <pwd.h>
#include <grp.h>

typedef struct {
    char *filepath;
    char *content;
} JLFileHandler;

JLFileHandler* create_jl_handler(const char *filepath) {
    JLFileHandler *handler = malloc(sizeof(JLFileHandler));
    handler->filepath = strdup(filepath);
    handler->content = NULL;
    return handler;
}

void destroy_jl_handler(JLFileHandler *handler) {
    if (handler->content) free(handler->content);
    free(handler->filepath);
    free(handler);
}

char* read_jl(JLFileHandler *handler) {
    // Read (decode) as text
    FILE *f = fopen(handler->filepath, "r");
    if (!f) {
        perror("Failed to open file");
        return NULL;
    }
    fseek(f, 0, SEEK_END);
    long size = ftell(f);
    fseek(f, 0, SEEK_SET);
    handler->content = malloc(size + 1);
    fread(handler->content, 1, size, f);
    handler->content[size] = '\0';
    fclose(f);
    return handler->content;
}

void write_jl(JLFileHandler *handler, const char *new_filepath, const char *content) {
    const char *write_content = content ? content : (handler->content ? handler->content : "");
    FILE *f = fopen(new_filepath, "w");
    if (!f) {
        perror("Failed to open file for writing");
        return;
    }
    fprintf(f, "%s", write_content);
    fclose(f);
}

void print_properties_jl(JLFileHandler *handler) {
    struct stat stats;
    if (stat(handler->filepath, &stats) != 0) {
        perror("Failed to get file stats");
        return;
    }

    printf("File name: %s\n", handler->filepath);
    printf("File size: %ld bytes\n", stats.st_size);
    printf("Creation time: %s", ctime(&stats.st_ctime));
    printf("Modification time: %s", ctime(&stats.st_mtime));
    printf("Access time: %s", ctime(&stats.st_atime));
    printf("Permissions: %o\n", stats.st_mode & 0777);
    printf("Owner UID: %d\n", stats.st_uid);
    printf("Group GID: %d\n", stats.st_gid);
    printf("File type: %s\n", S_ISREG(stats.st_mode) ? "regular file" : "other");
}

// Example usage:
// int main() {
//     JLFileHandler *handler = create_jl_handler("example.jl");
//     read_jl(handler);
//     print_properties_jl(handler);
//     write_jl(handler, "new_example.jl", "println(\"Hello, Julia!\")");
//     destroy_jl_handler(handler);
//     return 0;
// }