{"id":21428338,"url":"https://github.com/ushelp/easy-read-last-lines","last_synced_at":"2025-08-08T10:35:52.705Z","repository":{"id":57686026,"uuid":"491462988","full_name":"ushelp/easy-read-last-lines","owner":"ushelp","description":"Read the last N lines in the file. (like tail -n)","archived":false,"fork":false,"pushed_at":"2023-02-16T14:36:51.000Z","size":35,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-06T17:52:12.710Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ushelp.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":null,"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":["http://www.easyproject.cn/donation"]}},"created_at":"2022-05-12T10:15:36.000Z","updated_at":"2024-01-21T12:48:29.000Z","dependencies_parsed_at":"2022-09-18T23:13:13.931Z","dependency_job_id":null,"html_url":"https://github.com/ushelp/easy-read-last-lines","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/ushelp/easy-read-last-lines","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ushelp%2Feasy-read-last-lines","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ushelp%2Feasy-read-last-lines/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ushelp%2Feasy-read-last-lines/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ushelp%2Feasy-read-last-lines/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ushelp","download_url":"https://codeload.github.com/ushelp/easy-read-last-lines/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ushelp%2Feasy-read-last-lines/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264016735,"owners_count":23544626,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-22T22:12:48.517Z","updated_at":"2025-07-07T05:06:18.103Z","avatar_url":"https://github.com/ushelp.png","language":"JavaScript","funding_links":["http://www.easyproject.cn/donation"],"categories":[],"sub_categories":[],"readme":"# Easy-Read-Last-Lines\n\nHigh performance read the last N lines in the file or text across platforms. (like tail -n) \n\n## Table of contents\n\n- [Feature](#feature)\n- [Installation](#installation)\n- [Usage](#usage)\n- [Functions](#functions)\n- [License](#license)\n- [End](#end)\n\n## Feature\n- High performance read\n- Compatible with newlines on different platforms/format: `\\r`, `\\n`, `\\r\\n`\n- Support setting character `encoding`\n- Support get a `String` or `Buffer` object from file\n\n## Installation\n\n```BASH\nnpm install easy-read-last-lines\n```\n\n\n## Usage\n\n```JS\nconst erll = require('easy-read-last-lines');\n```\n\n### Read last N lines string from File\n\n```JS\nlet fielPath='YOUR_FILE_PATH';\n\n// Read last N lines string from File - Asynchronously\nerll.readFromFile(filePath, 3).then(function(lines) {\n    console.log(lines);\n}).catch(function(err) {\n    console.log(err.message);\n});\n\n//  Read last N lines string from File - Synchronously\nlet lines = await erll.readFromFile(filePath, 3, 'utf8');\nconsole.log(lines);\n\n// Read an array of last N line string from File\nlet linesArray = await erll.readArrayFromFile(filePath, 3, 'utf8');\nconsole.log(linesArray);\n\n```\n\n### Read last N lines buffer data from File\n\n```JS\nlet fielPath='YOUR_FILE_PATH';\n\n// Asynchronously\nerll.readBufferFromFile(filePath, 1).then(function(buffer) {\n    console.log(buffer.toString('base64'));\n}).catch(function(err) {\n    console.log(err.message);\n});\n\n// Synchronously\nlet buffer = await erll.readBufferFromFile(filePath, 1);\nconsole.log(buffer.toString('base64'));\n```\n\n### Read last N lines string from Text\n\n```JS\nvar text = `\nEasy \nRead \nLast\nLine`;\nvar text2 = `Easy\\nRead\\rLast\\r\\nLine`\n    \n// Read last N lines string from Text\nvar lines = erll.readFromText(text, 2);\nconsole.log(lines);\n\n// Read an array of last N line string from Text\nvar linesArray = erll.readArrayFromText(text2, 3);\nconsole.log(linesArray);\n```\n\n### Convert multiline text to array of string\n```JS\nvar text = `Easy\\nRead\\rLast\\r\\nLine`;\n\nconsole.log(erll.linesToArray(lines));\n```\n\n## Functions\n\n- **readFromFile(filePath, maxLine, [encoding]): Promise**\n    - `filePath`: file path(direct or relative path to file)\n    - `maxLine`: max number of last lines to read in\n    - `encoding`: When converting between Buffers and strings, a character encoding may be specified. If no character encoding is specified, `UTF-8` will be used as the default. [buffers-and-character-encodings](https://nodejs.org/api/buffer.html#buffers-and-character-encodings)    \n\n- **readArrayFromFile(filePath, maxLine, [encoding]): Promise**\n    - `filePath`: file path(direct or relative path to file)\n    - `maxLine`: max number of last lines to read in\n    - `encoding`: When converting between Buffers and strings, a character encoding may be specified. If no character encoding is specified, `UTF-8` will be used as the default. [buffers-and-character-encodings](https://nodejs.org/api/buffer.html#buffers-and-character-encodings)    \n\n- **readBufferFromFile(filePath, maxLine): Promise**\n    - `filePath`: file path(direct or relative path to file)\n    - `maxLine`: max number of last lines to read in\n    \n- **readFromText(text, maxLine): String**\n    - `text`: multiline string\n    - `maxLine`: max number of last lines to read in\n    \n- **readArrayFromText(text, maxLine): String**\n    - `text`: multiline string\n    - `maxLine`: max number of last lines to read in\n    \n- **linesToArray(text): Array**\n    - `text`: multiline string\n    \n## License\nMIT License\n\n## End\n\nEmail：\u003cinthinkcolor@gmail.com\u003e\n\n[http://www.easyproject.cn](http://www.easyproject.cn \"EasyProject Home\")\n\n\n**Donation/捐助:**\n\n\u003ca href=\"http://www.easyproject.cn/donation\"\u003e\n\u003cimg alt=\"\n支付宝/微信/QQ/云闪付/PayPal 扫码支付\" src=\"http://www.easyproject.cn/thanks/donation.png\"  title=\"支付宝/微信/QQ/云闪付/PayPal 扫码支付\"  height=\"320\" width=\"320\"\u003e\u003c/img\u003e\u003c/a\u003e\n\u003cdiv\u003e支付宝/微信/QQ/云闪付/PayPal\u003c/div\u003e\n\n\u003cbr/\u003e\n\n我们相信，每个人的点滴贡献，都将是推动产生更多、更好免费开源产品的一大步。\n\n**感谢慷慨捐助，以支持服务器运行和鼓励更多社区成员。**\n\nWe believe that the contribution of each bit by bit, will be driven to produce more and better free and open source products a big step.\n\n**Thank you donation to support the server running and encourage more community members.**","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fushelp%2Feasy-read-last-lines","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fushelp%2Feasy-read-last-lines","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fushelp%2Feasy-read-last-lines/lists"}