const bun = @import("root").bun; const string = bun.string; const Output = bun.Output; const toMutable = bun.constStrToU8; const Global = bun.Global; const Environment = bun.Environment; const strings = bun.strings; const MutableString = bun.MutableString; const stringZ = bun.stringZ; const default_allocator = bun.default_allocator; const C = bun.C; const PercentEncoding = @import("../url.zig").PercentEncoding; const std = @import("std"); const allocators = @import("../allocators.zig"); const URLPath = @This(); extname: string = "", path: string = "", pathname: string = "", first_segment: string = "", query_string: string = "", needs_redirect: bool = false, /// Treat URLs as non-sourcemap URLS /// Then at the very end, we check. is_source_map: bool = false, pub fn isRoot(this: *const URLPath, asset_prefix: string) bool { const without = this.pathWithoutAssetPrefix(asset_prefix); if (without.len == 1 and without[0] == '.') return true; return strings.eqlComptime(without, "index"); } // TODO: use a real URL parser // this treats a URL like /_next/ identically to / pub fn pathWithoutAssetPrefix(this: *const URLPath, asset_prefix: string) string { if (asset_prefix.len == 0) return this.path; const leading_slash_offset: usize = if (asset_prefix[0] == '/') 1 else 0; const base = this.path; const origin = asset_prefix[leading_slash_offset..]; const out = if (base.len >= origin.len and strings.eql(base[0..origin.len], origin)) base[origin.len..] else base; if (this.is_source_map and strings.endsWithComptime(out, ".map")) { return out[0 .. out.len - 4]; } return out; } // optimization: very few long strings will be URL-encoded // we're allocating virtual memory here, so if we never use it, it won't be allocated // and even when they're, they're probably rarely going to be > 1024 chars long // so we can have a big and little one and almost always use the little one threadlocal var temp_path_buf: [1024]u8 = undefined; threadlocal var big_temp_path_buf: [16384]u8 = undefined; pub fn parse(possibly_encoded_pathname_: string) !URLPath { var decoded_pathname = possibly_encoded_pathname_; var needs_redirect = false; if (strings.containsChar(decoded_pathname, '%')) { // https://github.com/ziglang/zig/issues/14148 var possibly_encoded_pathname: []u8 = switch (decoded_pathname.len) { 0...1024 => &temp_path_buf, else => &big_temp_path_buf, }; possibly_encoded_pathname = possibly_encoded_pathname[0..@min( possibly_encoded_pathname_.len, possibly_encoded_pathname.len, )]; bun.copy(u8, possibly_encoded_pathname, possibly_encoded_pathname_[0..possibly_encoded_pathname.len]); var clone = possibly_encoded_pathname[0..possibly_encoded_pathname.len]; var fbs = std.io.fixedBufferStream( // This is safe because: // - this comes from a non-const buffer // - percent *decoding* will always be <= length of the original string (no buffer overflow) toMutable( possibly_encoded_pathname, ), ); var writer = fbs.writer(); decoded_pathname = possibly_encoded_pathname[0..try PercentEncoding.decodeFaultTolerant(@TypeOf(writer), writer, clone, &needs_redirect, true)]; } var question_mark_i: i16 = -1; var period_i: i16 = -1; var first_segment_end: i16 = std.math.maxInt(i16); var last_slash: i16 = -1; var i: i16 = @as(i16, @intCast(decoded_pathname.len)) - 1; while (i >= 0) : (i -= 1) { const c = decoded_pathname[@as(usize, @intCast(i))]; switch (c) { '?' => { question_mark_i = @max(question_mark_i, i); if (question_mark_i < period_i) { period_i = -1; } if (last_slash > question_mark_i) { last_slash = -1; } }, '.' => { period_i = @max(period_i, i); }, '/' => { last_slash = @max(last_slash, i); if (i > 0) { first_segment_end = @min(first_segment_end, i); } }, else => {}, } } if (last_slash > period_i) { period_i = -1; } // .js.map // ^ const extname = brk: { if (question_mark_i > -1 and period_i > -1) { period_i += 1; break :brk decoded_pathname[@as(usize, @intCast(period_i))..@as(usize, @intCast(question_mark_i))]; } else if (period_i > -1) { period_i += 1; break :brk decoded_pathname[@as(usize, @intCast(period_i))..]; } else { break :brk &([_]u8{}); } }; var path = if (question_mark_i < 0) decoded_pathname[1..] else decoded_pathname[1..@as(usize, @intCast(question_mark_i))]; const first_segment = decoded_pathname[1..@min(@as(usize, @intCast(first_segment_end)), decoded_pathname.len)]; const is_source_map = strings.eqlComptime(extname, "map"); var backup_extname: string = extname; if (is_source_map and path.len > ".map".len) { if (std.mem.lastIndexOfScalar(u8, path[0 .. path.len - ".map".len], '.')) |j| { backup_extname = path[j + 1 ..]; backup_extname = backup_extname[0 .. backup_extname.len - ".map".len]; path = path[0 .. j + backup_extname.len + 1]; } } return URLPath{ .extname = if (!is_source_map) extname else backup_extname, .is_source_map = is_source_map, .pathname = decoded_pathname, .first_segment = first_segment, .path = if (decoded_pathname.len == 1) "." else path, .query_string = if (question_mark_i > -1) decoded_pathname[@as(usize, @intCast(question_mark_i))..@as(usize, @intCast(decoded_pathname.len))] else "", .needs_redirect = needs_redirect, }; } ace-packages Unnamed repository; edit this file 'description' to name the repository.
aboutsummaryrefslogtreecommitdiff
path: root/docs/guides/read-file/arraybuffer.md (unfollow)
AgeCommit message (Expand)AuthorFilesLines
2023-08-23Update globals.d.ts (#4276)Gravatar VietnamecDevelopment 1-1/+1
2023-08-23Fix ffi type (#4265)Gravatar Code Hz 2-49/+272
2023-08-23Bunch of streams fixes (#4251)Gravatar Jarred Sumner 31-548/+866
2023-08-23docs: remove broken DNS link which is also not present in the official docs (...Gravatar Quentin 1-1/+0
2023-08-23Fix more types. (#4273)Gravatar xxxhussein 8-16/+22
2023-08-23ask for bun --revision instead bun -v (#4256)Gravatar Jozef Steinhübl 1-1/+1
2023-08-22fix yield (#4264)Gravatar dave caruso 2-1/+17
2023-08-22Fix Bun.inspect typesGravatar Colin McDonnell 1-1/+1
2023-08-21fix fsevents and stub for qwikcity (#4247)Gravatar dave caruso 9-64/+24
2023-08-21fix stdin stream unref and resuming (#4250)Gravatar Dylan Conway 4-19/+26
2023-08-21Docs and types for v0.8.0 (#4199)Gravatar Colin McDonnell 10-37/+487
2023-08-21Bun v0.8Gravatar Jarred Sumner 5-5/+5
2023-08-21Make the code generator less duplicativeGravatar Jarred Sumner 2-84/+39
2023-08-21import errors have `code` set to `ERR_MODULE_NOT_FOUND` and `require` errors ...Gravatar Jarred Sumner 11-19/+122
2023-08-21fetch(stream) add stream support for compressed and uncompressed data (#4127)Gravatar Ciro Spaciari 19-156/+1876
2023-08-21Fix inquirer (#4245)Gravatar dave caruso 2-3/+6
2023-08-21Update module_loader.zigGravatar Jarred Sumner 1-1/+1
2023-08-21Fix(bundler): allow generating exe file in nested path. (#4226)Gravatar Ai Hoshino 3-7/+49
2023-08-21Fix typoGravatar Colin McDonnell 1-1/+1
2023-08-21Fix crypto.EC constructor (#4242)Gravatar dave caruso 2-3/+4
2023-08-21Implement `napi_ref_threadsafe_function` (#4156)Gravatar dave caruso 10-7/+65
2023-08-21feat: Implement Bun.inspect.custom (#4243)Gravatar dave caruso 6-8/+26
2023-08-21Fixes #4089 (#4105)Gravatar Jarred Sumner 3-36/+136
2023-08-2140x faster .toString('hex') (#4237)Gravatar Jarred Sumner 3-17/+105
2023-08-21Fix memory leak in `buffer.toString("hex")` (#4235)Gravatar Jarred Sumner 2-1/+6
2023-08-21Update README.md (#4232)Gravatar xxxhussein 1-1/+1
2023-08-21Add missing header changeGravatar Jarred Sumner 1-1/+1
2023-08-21Add LazyPropertyGravatar Jarred Sumner 1-0/+3
2023-08-21Fix BigIntStats generated classGravatar Jarred Sumner 1-1/+1
2023-08-21RegenerateGravatar Jarred Sumner 1-8/+15
2023-08-21Implement FileGravatar Jarred Sumner 12-12/+387
2023-08-20Fixes #1675 (#4230)Gravatar Jarred Sumner 8-70/+297
2023-08-20Implement `--inspect-brk` (#4222)Gravatar Jarred Sumner 17-41/+101
2023-08-20Fix test failures from 3a9a6c63a (#4231)Gravatar Jarred Sumner 4-32/+34
2023-08-20Fix(bundler): use different alias mappings based on the target. (#4163)Gravatar Ai Hoshino 8-18/+90
2023-08-19Update BunDebugger.cppGravatar Jarred Sumner 1-1/+3
2023-08-19Introduce `bun --inspect-wait`Gravatar Jarred Sumner 3-19/+47
2023-08-19misc non-posix fixesGravatar Jarred Sumner 2-3/+3
2023-08-19Update lockfile.mdGravatar Jarred Sumner 1-1/+8
2023-08-19Update lockfile.mdGravatar Jarred Sumner 1-4/+4
2023-08-19Update lockfile.mdGravatar Jarred Sumner 1-1/+29
2023-08-19Update Dockerfile-distroless (#4210)Gravatar Omar 1-0/+1
2023-08-19Fix symbol visibilityGravatar Jarred Sumner 1-0/+1
2023-08-19[napi] Implement `node_api_create_syntax_error`, `node_api_symbol_for`, `nod...Gravatar Jarred Sumner 5-1/+70
2023-08-19Fix crash impacting sharp & resvg (#4221)Gravatar Jarred Sumner 5-73/+73
2023-08-19Fixes #172 (#4220)Gravatar Jarred Sumner 7-9/+87
2023-08-19Add inline sourcemaps when `--inspect` is enabled (#4213)Gravatar Jarred Sumner 3-3/+64
2023-08-19tty `ReadStream`, `WriteStream`, and readline rawmode (#4179)Gravatar Dylan Conway 23-722/+821
2023-08-18Fix make headers (again)Gravatar Jarred Sumner 1-0/+2