Task 240: .FQL File Format
Task 240: .FQL File Format
1. List of all the properties of this file format intrinsic to its file system
The .FQL file format is a plain text source file used for Fauna Query Language (FQL) scripts in FaunaDB (a serverless database). It has no binary structure, headers, or footers; it is simply human-readable text containing FQL code that can be evaluated or imported into a Fauna database. Based on documentation and examples, the intrinsic properties related to its file system storage and structure are:
- File type: Regular text file (not binary or compressed).
- Encoding: UTF-8 (standard for source code files to support international characters in queries).
- Line endings: Platform-dependent (typically LF on Unix/Linux/macOS, CRLF on Windows), but parsed as newline-separated statements.
- MIME type: text/plain.
- Size: Variable, determined by the length of the FQL script (no fixed size or padding).
- Structure: Line-based or semicolon-separated FQL expressions; no metadata blocks or embedded binary data.
- Permissions: Standard file permissions (readable/writable as a text file).
- No indexing or fragmentation: Stored as a contiguous file on disk, like any plain text file.
These properties make it lightweight and editable in any text editor.
2. Two direct download links for files of format .FQL
- https://raw.githubusercontent.com/fauna-labs/fauna-schema-migrate/main/tests/general/multi_update_noop/resources2/create_collection.fql (A sample .FQL file creating a Fauna collection from the Fauna Schema Migrate tool tests).
- https://git.isis.vanderbilt.edu/feisele/fql/-/raw/recasting/contrib/FQL_Examples/strength.fql (A sample .FQL file with a query example from the Functorial Query Language project, demonstrating .FQL usage in a different but compatible context).
3. Ghost blog embedded HTML JavaScript for drag n drop .FQL file and dump properties
Embed this full HTML snippet into a Ghost blog post (use the HTML card in the editor). It creates a drag-and-drop zone that reads the dropped .FQL file as text, extracts the properties from point 1, and dumps them to the screen in a formatted div.
Drag and drop a .FQL file here to analyze its properties.
4. Python class for .FQL file handling
This class opens a .FQL file, reads/decodes it as UTF-8 text, prints the properties, and supports writing back the content.
import os
class FQLFileHandler:
def __init__(self, file_path):
self.file_path = file_path
self.content = None
self.properties = {}
def read(self):
if not os.path.exists(self.file_path):
raise FileNotFoundError(f"{self.file_path} not found")
with open(self.file_path, 'r', encoding='utf-8') as f:
self.content = f.read()
self._extract_properties()
self._print_properties()
def _extract_properties(self):
self.properties = {
'File type': 'Regular text file',
'Encoding': 'UTF-8',
'Line endings': 'CRLF (Windows)' if '\r\n' in self.content else 'LF (Unix)',
'MIME type': 'text/plain',
'Size': len(self.content),
'Structure': 'Line-based FQL expressions' if len(self.content.splitlines()) > 1 else 'Single-line FQL',
'Permissions': oct(os.stat(self.file_path).st_mode)[-3:],
'No indexing or fragmentation': 'Contiguous file on disk'
}
def _print_properties(self):
print("FQL File Properties:")
for key, value in self.properties.items():
print(f"{key}: {value}")
print(f"Content preview: {self.content[:500]}...")
def write(self, output_path=None):
if output_path is None:
output_path = self.file_path
with open(output_path, 'w', encoding='utf-8') as f:
f.write(self.content)
print(f"Written to {output_path}")
# Example usage:
# handler = FQLFileHandler('example.fql')
# handler.read()
# handler.write('output.fql')
5. Java class for .FQL file handling
This class opens a .FQL file, reads/decodes it as UTF-8 text using NIO, prints the properties, and supports writing back.
import java.nio.file.*;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
public class FQLFileHandler {
private final Path filePath;
private String content;
private Map<String, Object> properties = new HashMap<>();
public FQLFileHandler(String filePathStr) {
this.filePath = Paths.get(filePathStr);
}
public void read() throws Exception {
if (!Files.exists(filePath)) {
throw new java.nio.file.NoSuchFileException(filePath.toString());
}
content = Files.readString(filePath, StandardCharsets.UTF_8);
extractProperties();
printProperties();
}
private void extractProperties() throws Exception {
properties.put("File type", "Regular text file");
properties.put("Encoding", "UTF-8");
String lineEndings = content.contains("\r\n") ? "CRLF (Windows)" : "LF (Unix)";
properties.put("Line endings", lineEndings);
properties.put("MIME type", "text/plain");
properties.put("Size", content.length());
long lineCount = content.lines().count();
String structure = lineCount > 1 ? "Line-based FQL expressions" : "Single-line FQL";
properties.put("Structure", structure);
properties.put("Permissions", Integer.toOctalString((int) Files.getPosixFilePermissions(filePath).hashCode()));
properties.put("No indexing or fragmentation", "Contiguous file on disk");
}
private void printProperties() {
System.out.println("FQL File Properties:");
for (Map.Entry<String, Object> entry : properties.entrySet()) {
System.out.println(entry.getKey() + ": " + entry.getValue());
}
System.out.println("Content preview: " + content.substring(0, Math.min(500, content.length())) + "...");
}
public void write(String outputPathStr) throws Exception {
Path outputPath = Paths.get(outputPathStr);
Files.writeString(outputPath, content, StandardCharsets.UTF_8);
System.out.println("Written to " + outputPath);
}
// Example usage:
// FQLFileHandler handler = new FQLFileHandler("example.fql");
// handler.read();
// handler.write("output.fql");
}
6. JavaScript class for .FQL file handling
This class uses the File API to read a .FQL file (e.g., from drag-drop or input), decodes as UTF-8 text, prints properties to console, and supports writing (via Blob for download).
class FQLFileHandler {
constructor(file) {
this.file = file;
this.content = null;
this.properties = {};
}
async read() {
if (!this.file || !this.file.name.endsWith('.fql')) {
throw new Error('Invalid .FQL file');
}
this.content = await this.file.text();
this.extractProperties();
this.printProperties();
}
extractProperties() {
this.properties = {
'File type': 'Regular text file',
'Encoding': 'UTF-8',
'Line endings': this.content.includes('\r\n') ? 'CRLF (Windows)' : 'LF (Unix)',
'MIME type': 'text/plain',
'Size': this.content.length,
'Structure': this.content.split(/\r?\n/).length > 1 ? 'Line-based FQL expressions' : 'Single-line FQL',
'Permissions': 'Standard file permissions (browser-limited)',
'No indexing or fragmentation': 'Contiguous file on disk'
};
}
printProperties() {
console.log('FQL File Properties:');
Object.entries(this.properties).forEach(([key, value]) => {
console.log(`${key}: ${value}`);
});
console.log(`Content preview: ${this.content.substring(0, 500)}...`);
}
write(filename = this.file.name) {
const blob = new Blob([this.content], { type: 'text/plain;charset=utf-8' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = filename;
a.click();
URL.revokeObjectURL(url);
console.log(`Downloaded as ${filename}`);
}
// Example usage (in browser):
// const input = document.querySelector('input[type="file"]');
// input.addEventListener('change', (e) => {
// const handler = new FQLFileHandler(e.target.files[0]);
// handler.read().then(() => handler.write('output.fql'));
// });
}
7. C class (struct with functions) for .FQL file handling
This uses standard C stdio for reading/writing UTF-8 text (assuming Unix-like system; for Windows, adjust line endings). Compile with gcc fql_handler.c -o fql_handler
.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>
typedef struct {
char* file_path;
char* content;
size_t content_size;
char* properties[8]; // Fixed array for properties
} FQLFileHandler;
FQLFileHandler* fql_create(const char* file_path) {
FQLFileHandler* handler = malloc(sizeof(FQLFileHandler));
handler->file_path = strdup(file_path);
handler->content = NULL;
handler->content_size = 0;
for (int i = 0; i < 8; i++) handler->properties[i] = NULL;
return handler;
}
void fql_free(FQLFileHandler* handler) {
free(handler->file_path);
free(handler->content);
for (int i = 0; i < 8; i++) free(handler->properties[i]);
free(handler);
}
int fql_read(FQLFileHandler* handler) {
FILE* f = fopen(handler->file_path, "r");
if (!f) return -1;
fseek(f, 0, SEEK_END);
handler->content_size = ftell(f);
fseek(f, 0, SEEK_SET);
handler->content = malloc(handler->content_size + 1);
fread(handler->content, 1, handler->content_size, f);
handler->content[handler->content_size] = '\0';
fclose(f);
// Extract properties (simplified)
handler->properties[0] = strdup("File type: Regular text file");
handler->properties[1] = strdup("Encoding: UTF-8");
char* line_end = strstr(handler->content, "\r\n") ? "CRLF (Windows)" : "LF (Unix)";
char le[50]; sprintf(le, "Line endings: %s", line_end);
handler->properties[2] = strdup(le);
handler->properties[3] = strdup("MIME type: text/plain");
char sz[20]; sprintf(sz, "Size: %zu", handler->content_size);
handler->properties[4] = strdup(sz);
int lines = 1;
for (size_t i = 0; i < handler->content_size; i++) if (handler->content[i] == '\n') lines++;
char struct_str[50]; sprintf(struct_str, "Structure: %s", lines > 1 ? "Line-based FQL expressions" : "Single-line FQL");
handler->properties[5] = strdup(struct_str);
struct stat st;
stat(handler->file_path, &st);
char perm[20]; sprintf(perm, "Permissions: %o", st.st_mode & 0777);
handler->properties[6] = strdup(perm);
handler->properties[7] = strdup("No indexing or fragmentation: Contiguous file on disk");
fql_print_properties(handler);
return 0;
}
void fql_print_properties(FQLFileHandler* handler) {
printf("FQL File Properties:\n");
for (int i = 0; i < 8 && handler->properties[i]; i++) {
printf("%s\n", handler->properties[i]);
}
printf("Content preview: %.*s...\n", 500, handler->content);
}
int fql_write(FQLFileHandler* handler, const char* output_path) {
FILE* f = fopen(output_path, "w");
if (!f) return -1;
fwrite(handler->content, 1, handler->content_size, f);
fclose(f);
printf("Written to %s\n", output_path);
return 0;
}
// Example usage:
// int main() {
// FQLFileHandler* h = fql_create("example.fql");
// if (fql_read(h) == 0) {
// fql_write(h, "output.fql");
// }
// fql_free(h);
// return 0;
// }